* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Programming Languages and Paradigms
Programming language wikipedia , lookup
Go (programming language) wikipedia , lookup
Abstraction (computer science) wikipedia , lookup
Reserved word wikipedia , lookup
Functional programming wikipedia , lookup
Reactive programming wikipedia , lookup
C Sharp (programming language) wikipedia , lookup
Falcon (programming language) wikipedia , lookup
Corecursion wikipedia , lookup
Object-oriented programming wikipedia , lookup
Programming Languages and Paradigms Introduction Definitions Programming Language notation for specifying programs/computations consists of words, symbols, and rules for writing a program Programming Paradigm 5/24/2017 programming “technique” way of thinking about programming view of a program Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 2 Programming Paradigms Imperative Programming Object-Oriented Programming program as a collection of classes for interacting objects Functional Programming program as a collection of statements and procedures affecting data (variables) program as a collection of (math) functions Others 5/24/2017 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 3 Some Languages by Paradigm Imperative (also called Structured or Procedural) Programming Object-Oriented Programming FORTRAN, BASIC, COBOL, Pascal, C SmallTalk, C++, Java Functional Programming 5/24/2017 LISP, ML, Haskell Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 4 History of Languages 1950s to 1960s 1960s to 1970s (ALGOL-based) Pascal and others 1970s to 1980s FORTRAN, COBOL, LISP, BASIC Prolog, C, Ada 1980s to 1990s 5/24/2017 C++, ML, Perl, Java Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 5 Paradigm Change For example, from Procedural to ObjectOriented Programming Arises from problems encountered in one paradigm but addressed in another Case study: from C to C++ 5/24/2017 Evolution from procedural, to modular, to objectbased, to object-oriented programming Stroustrup book section 1.2 (2nd edition, pp. 14-22): required reading material Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 6 Case Study: Stacks Stack last-in, first-out structure operations: push, pop Stacks are used to support some solution 5/24/2017 push and pop are defined and implemented as functions the solution consists of code that invoke these functions Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 7 Implementing a Stack Stack can be implemented as an array Or as a linked list array contains pushed elements an integer refers to top of the stack most common implementation using pointers and dynamic allocation Other implementations 5/24/2017 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 8 Array Implementation in C char Store[MAX]; int top = 0; void push(char x) { if (top < MAX) Store[top++] = x; else printf(“full\n”); } 5/24/2017 char pop() { if (top > 0) return Store[--top]; else printf(“empty\n”); } ... Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 9 Using the Stack void application() { … push(‘x’); … result = pop(); … } 5/24/2017 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 10 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) 5/24/2017 one source file Store and top are global variables stack and application functions defined at the same level (file) Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 11 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 5/24/2017 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 12 Encapsulation and Modular Programming Focus is on writing good modules hide implementation details from user provide an interface Stack example 5/24/2017 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 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 13 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? 5/24/2017 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 14 Multiple Stacks Strategy 1 (use structs) 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) 5/24/2017 implement multiple data structures in stack.c use an integer (the handle) to specify “stack number” Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 15 Modules and Multiple Stacks Disadvantage of strategy 1: implementation (data) is exposed back to original problem on stack integrity Disadvantage of strategy 2: 5/24/2017 stack module will be unnecessarily complex handle is artificial (what if an arbitrary integer is passed?) Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 16 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++) 5/24/2017 stack.h and stack.cpp define a stack class Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 17 Object-Oriented Programming Incorporates both encapsulation and inheritance through the class concept Focus is on writing good classes and on code reuse Examples 5/24/2017 Shape, Circle, and Rectangle in a drawing program Employee, Faculty, Staff in a university personnel system Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 18 What’s Next? Survey of languages by paradigm Discussion of language features and language design decisions Related areas: language implementation, translation, syntax, semantics 5/24/2017 Copyright 2008, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 19