SlideShare a Scribd company logo
Programming Paradigms
Introduction
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 2
Definitions
 Programming Language
 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 5
History of Languages
 1950s to 1960s
 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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. 14-22):
required reading material
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 7
Case Study: Stacks
 Stack
 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 9
Array Implementation in C
char Store[MAX];
int top = 0;
void push(char x)
{
if (top < MAX)
Store[top++] = x;
else
printf(“fulln”);
}
char pop()
{
if (top > 0)
return Store[--top];
else
printf(“emptyn”);
}
...
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 10
Using the Stack
void application()
{
…
push(‘x’);
…
result = pop();
…
}
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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)
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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?
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 15
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)
 implement multiple data structures in stack.c
 use an integer (the handle) to specify “stack
number”
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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?)
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 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
6/15/2005
Copyright 2005, by the authors of these slides, and Ateneo de
Manila University. All rights reserved.
L1: Introduction
Slide 19
What’s Next?
 Survey of languages by paradigm
 Discussion of language features and
language design decisions
 Related areas: language implementation,
translation, syntax, semantics

More Related Content

Similar to PLP-L1-Intro.ppt

1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docx
honey725342
 
Software engineering
Software engineeringSoftware engineering
Software engineering
Fahe Em
 
Software engineering
Software engineeringSoftware engineering
Software engineering
Fahe Em
 
javagruppen.dk - e4, the next generation Eclipse platform
javagruppen.dk - e4, the next generation Eclipse platformjavagruppen.dk - e4, the next generation Eclipse platform
javagruppen.dk - e4, the next generation Eclipse platform
Tonny Madsen
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
The application of computer aided learning to learn basic concepts of branchi...
The application of computer aided learning to learn basic concepts of branchi...The application of computer aided learning to learn basic concepts of branchi...
The application of computer aided learning to learn basic concepts of branchi...
ijma
 
ALT
ALTALT
ANSI ISO C Professional Programmer S Handbook
ANSI ISO C   Professional Programmer S HandbookANSI ISO C   Professional Programmer S Handbook
ANSI ISO C Professional Programmer S Handbook
Nicole Heredia
 
Pooling optimization problem
Pooling optimization problemPooling optimization problem
Pooling optimization problem
Alkis Vazacopoulos
 
A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...
Sabrina Ball
 
Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++
Nimrita Koul
 
IP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeIP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG Programme
SAFAD ISMAIL
 
Stl
StlStl
Eclipse Banking Day in Copenhagen - Eclipse RCP as an Application Platform
Eclipse Banking Day in Copenhagen - Eclipse RCP as an Application PlatformEclipse Banking Day in Copenhagen - Eclipse RCP as an Application Platform
Eclipse Banking Day in Copenhagen - Eclipse RCP as an Application Platform
Tonny Madsen
 
Cprogramminginterviewquestions 120622074544-phpapp01
Cprogramminginterviewquestions 120622074544-phpapp01Cprogramminginterviewquestions 120622074544-phpapp01
Cprogramminginterviewquestions 120622074544-phpapp01
chandu_microcosm
 
Javascript
JavascriptJavascript
Javascript
Sheldon Abraham
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
siragezeynu
 
T2
T2T2
T2
lksoo
 
Computer Programming - Lecture E
Computer Programming - Lecture EComputer Programming - Lecture E
Computer Programming - Lecture E
CMDLearning
 
The Concurrency Challenge : Notes
The Concurrency Challenge : NotesThe Concurrency Challenge : Notes
The Concurrency Challenge : Notes
Subhajit Sahu
 

Similar to PLP-L1-Intro.ppt (20)

1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docx
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
javagruppen.dk - e4, the next generation Eclipse platform
javagruppen.dk - e4, the next generation Eclipse platformjavagruppen.dk - e4, the next generation Eclipse platform
javagruppen.dk - e4, the next generation Eclipse platform
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 
The application of computer aided learning to learn basic concepts of branchi...
The application of computer aided learning to learn basic concepts of branchi...The application of computer aided learning to learn basic concepts of branchi...
The application of computer aided learning to learn basic concepts of branchi...
 
ALT
ALTALT
ALT
 
ANSI ISO C Professional Programmer S Handbook
ANSI ISO C   Professional Programmer S HandbookANSI ISO C   Professional Programmer S Handbook
ANSI ISO C Professional Programmer S Handbook
 
Pooling optimization problem
Pooling optimization problemPooling optimization problem
Pooling optimization problem
 
A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...
 
Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++
 
IP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeIP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG Programme
 
Stl
StlStl
Stl
 
Eclipse Banking Day in Copenhagen - Eclipse RCP as an Application Platform
Eclipse Banking Day in Copenhagen - Eclipse RCP as an Application PlatformEclipse Banking Day in Copenhagen - Eclipse RCP as an Application Platform
Eclipse Banking Day in Copenhagen - Eclipse RCP as an Application Platform
 
Cprogramminginterviewquestions 120622074544-phpapp01
Cprogramminginterviewquestions 120622074544-phpapp01Cprogramminginterviewquestions 120622074544-phpapp01
Cprogramminginterviewquestions 120622074544-phpapp01
 
Javascript
JavascriptJavascript
Javascript
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
T2
T2T2
T2
 
Computer Programming - Lecture E
Computer Programming - Lecture EComputer Programming - Lecture E
Computer Programming - Lecture E
 
The Concurrency Challenge : Notes
The Concurrency Challenge : NotesThe Concurrency Challenge : Notes
The Concurrency Challenge : Notes
 

Recently uploaded

一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
AlvianRamadhani5
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
Addu25809
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
sachin chaurasia
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
mahaffeycheryld
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
Shiny Christobel
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
Prakhyath Rai
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
um7474492
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 

Recently uploaded (20)

一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 

PLP-L1-Intro.ppt

  • 2. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 2 Definitions  Programming Language  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
  • 3. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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
  • 5. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 5 History of Languages  1950s to 1960s  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
  • 6. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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. 14-22): required reading material
  • 7. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 7 Case Study: Stacks  Stack  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
  • 8. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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
  • 9. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 9 Array Implementation in C char Store[MAX]; int top = 0; void push(char x) { if (top < MAX) Store[top++] = x; else printf(“fulln”); } char pop() { if (top > 0) return Store[--top]; else printf(“emptyn”); } ...
  • 10. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 10 Using the Stack void application() { … push(‘x’); … result = pop(); … }
  • 11. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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)
  • 12. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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
  • 13. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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
  • 14. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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?
  • 15. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 15 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)  implement multiple data structures in stack.c  use an integer (the handle) to specify “stack number”
  • 16. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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?)
  • 17. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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
  • 18. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 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
  • 19. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1: Introduction Slide 19 What’s Next?  Survey of languages by paradigm  Discussion of language features and language design decisions  Related areas: language implementation, translation, syntax, semantics