Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Languages and Paradigms

Similar presentations


Presentation on theme: "Programming Languages and Paradigms"— Presentation transcript:

1 Programming Languages and Paradigms
Introduction

2 Definitions Programming Language Programming Paradigm
notation for specifying programs/computations consists of words, symbols, and rules for writing a program Programming Paradigm programming “technique” way of thinking about programming view of a program 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

3 Programming Paradigms
Imperative Programming program as a collection of statements and procedures affecting data (variables) Object-Oriented Programming program as a collection of classes for interacting objects Functional Programming program as a collection of (math) functions Others 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

4 Some Languages by Paradigm
Imperative (also called Structured or Procedural) Programming FORTRAN, BASIC, COBOL, Pascal, C Object-Oriented Programming SmallTalk, C++, Java Functional Programming LISP, ML, Haskell 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

5 History of Languages 1950s to 1960s 1960s to 1970s 1970s to 1980s
FORTRAN, COBOL, LISP, BASIC 1960s to 1970s (ALGOL-based) Pascal and others 1970s to 1980s Prolog, C, Ada 1980s to 1990s C++, ML, Perl, Java 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

6 Paradigm Change For example, from Procedural to Object-Oriented Programming Arises from problems encountered in one paradigm but addressed in another Case study: from C to C++ Evolution from procedural, to modular, to object-based, to object-oriented programming Stroustrup book section 1.2 (2nd edition, pp ): required reading material 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

7 Case Study: Stacks Stack Stacks are used to support some solution
last-in, first-out structure operations: push, pop Stacks are used to support some solution push and pop are defined and implemented as functions the solution consists of code that invoke these functions 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

8 Implementing a Stack Stack can be implemented as an array
array contains pushed elements an integer refers to top of the stack most common implementation Or as a linked list using pointers and dynamic allocation Other implementations 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

9 Array Implementation in C
char Store[MAX]; int top = 0; void push(char x) { if (top < MAX) Store[top++] = x; else printf(“full\n”); } char pop() { if (top > 0) return Store[--top]; else printf(“empty\n”); } ... 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

10 Using the Stack void application() { … push(‘x’); result = pop(); }
4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

11 Procedural Programming
Focus is on writing good functions and procedures use the most appropriate implementation and employ correct efficient algorithms Stack example (assume array implementation) one source file Store and top are global variables stack and application functions defined at the same level (file) 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

12 Problems Application can alter implementation details
can directly manipulate top and Store from application() integrity of stack not ensured Stack code and application code are not separated 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

13 Encapsulation and Modular Programming
Focus is on writing good modules hide implementation details from user provide an interface Stack example stack.h contains prototypes for push, pop stack.c contains stack code, Store and top declared static (local to stack.c) application includes stack.h 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

14 Benefits from Modules Application cannot destroy the integrity of the stack Stack implementation can change without affecting application source Question: what happens if we need more than one stack? 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

15 Multiple Stacks Strategy 1 (use structs) Strategy 2 (use handles)
in stack.h, define a stack structure that contains Store and top; push, pop now have an extra parameter that specifies which stack application code defines stack variables Strategy 2 (use handles) implement multiple data structures in stack.c use an integer (the handle) to specify “stack number” 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

16 Modules and Multiple Stacks
Disadvantage of strategy 1: implementation (data) is exposed back to original problem on stack integrity Disadvantage of strategy 2: stack module will be unnecessarily complex handle is artificial (what if an arbitrary integer is passed?) 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

17 Abstract Data Types and Object-based Programming
Focus is on writing good classes (or types) that define operations on objects of the class class defined like a module (encapsulation enforced) but multiple instances now possible user-defined type Stack example (C++) stack.h and stack.cpp define a stack class 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

18 Object-Oriented Programming
Incorporates both encapsulation and inheritance through the class concept Focus is on writing good classes and on code reuse Examples Shape, Circle, and Rectangle in a drawing program Employee, Faculty, Staff in a university personnel system 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

19 What’s Next? Survey of languages by paradigm
Discussion of language features and language design decisions Related areas: language implementation, translation, syntax, semantics 4/18/2019 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved.


Download ppt "Programming Languages and Paradigms"

Similar presentations


Ads by Google