IT 240
Programming Paradigms
MS Information Technology
Ateneo de Davao
Course Outline
Programming Language Concepts
Survey of Languages and Paradigms
Imperative, Functional, Object-Oriented
Focus: OO Programming
OO Languages (Java and C++)
OO Design (UML)
Design Patterns
Prerequisites and Context
IT 240: One of the six required (core)
courses in the MS IT curriculum
Assumes sufficient exposure (at least two
semesters) to programming
preferably in the C Language
undergraduate courses in data structures
and/or programming languages will be helpful
Programming Language Concepts, by
Ghezzi and Jazayeri
Concepts of Programming Languages, by
The C++ Programming Language, by
Course Requirements
Midterm Exam
Final Exam
Individual Report
Session 1: Overview,
Imperative Prog (November)
Session 2: Functional Prog (December)
Session 3: OO Programming (January)
Session 4: More OOP, Reports (February)
Final Exam
Schedule This Weekend
Friday Afternoon
Overview, Classification of Languages
Saturday Morning
Evolution from Imperative/Structured
Programming to OO Programming
Saturday Afternoon
Syntax and Semantics, Language Translation
Concepts in Imperative Programming
Revised Schedule This
Saturday Afternoon Session 1:
Overview, Classification of Languages
Evolution from Imperative/Structured Programming
to OO Programming
Saturday Afternoon/Evening Session 2:
Syntax and Semantics, Language Translation
Concepts in Imperative Programming
Sunday Morning session
Imperative Programming, continued
Introduction to Java (time permitting)
Session Format
discussion of formal definitions, concepts
and cases
implementation of examples discussed
exercises to be submitted
Objective: gain working knowledge of the
topics discussed
Course Material and
Required Reading
Visit course website regularly:
will link to a page containing IT 240 material
Stroustrup book: section on Programming
Paradigms (sec. 1.2, pp. 14-22)
Overview of
Programming Paradigms
IT 240
Programming Paradigm
programming “technique” (?)
way of thinking about programming
view of a program
Programming Language
consists of words, symbols, and rules for
writing a program
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
Some Languages by
Imperative (also called Structured or
Procedural) Programming
Object-Oriented Programming
SmallTalk, C++, Java
Functional Programming
LISP, ML, Haskell
History of Languages
1950s to 1960s
1960s to 1970s
(ALGOL-based) Pascal and others
1970s to 1980s
Prolog, C, Ada
1980s to 1990s
C++, ML, Perl, Java
Paradigm Change
For example, from Structured to ObjectOriented
Arises from problems encountered in one
paradigm but addressed in another
Case study: from C to C++
Evolution from structured, to modular, to
object-based, to object-oriented programming
Stroustrup book section 1.2
Case Study: Stacks
last-in, first-out structure
operations: push, pop
Sample uses ?
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
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
Array Implementation in C
char Store[MAX];
int top = 0;
void push(char x)
if (top < MAX)
Store[top++] = x;
char pop()
if (top > 0)
return Store[--top];
Using the Stack
void application()
result = pop();
Procedural Programming
Focus is on writing good functions and
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)
Application can alter implementation
can directly manipulate top and Store from
integrity of stack not ensured
Stack code and application code are not
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
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?
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
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?)
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
Incorporates both encapsulation and
inheritance through the class concept
Focus is on writing good classes and on
code reuse
Shape, Circle, and Rectangle in a drawing
Employee, Faculty, Staff in a university
personnel system
Lab Exercises (Set 1)
Modular Programming
create a stack module
Multiple stacks
create a multiple-stack module using
create a multiple-stack module using handles
Object-based Programming
create a stack class in C++
Syntax and Semantics
IT 240
Language Definition
syntactic vs semantic rules
Translation & Language Processing
Language Definition
set of rules that define form
BNF Grammar or syntax diagram
specify meaning of well-formed programs
formal semantics: pre- and post- conditions
Specifying Syntax
Lexical Rules
rules for determining tokens
tokens: syntactic units (e.g., number,
identifier, semicolon, equals)
Syntactic Rules
Grammar: set of productions
productions: terminals (tokens) and
Given a language construct
what is required for that (well-formed)
construct to execute?
what happens upon execution?
Example: assignment statement
tokens present? syntax? semantics?
Language Translation
processes instructions on the fly
produces object code for execution
Intermediate code
e.g., pcode or the Java Virtual Machine
Compilation Stages
Lexical Analysis
Parsing (Syntax Analysis)
Code Generation
Code Optimization
* Symbol Table Management
For the sample program, simulate
compilation and describe effect for each
compilation stage
Lab exercise (Set 2)
Simple exercise on Lexical Analysis,
Parsing, and Symbol table management
Parser for variable declarations (C & Pascal)
Output: list of variables per data type
Imperative Programming
IT 240
Imperative Programming
Variables, assignment, sequencing,
iteration, procedures as units
State-based, assignment-oriented
Global variables, side effects
Program units: Data (Variables) and
Computation (Statements and Routines)
Data and Computation
Data types
Assignments and expressions
Control structures
Subprograms / routines
Program units/entities have attributes
e.g., a variable has a name, a statement has
associated actions
setting the value of an attribute
Binding time
when binding occurs
Binding Time
Language definition time
Language implementation time
A named location in memory that can
hold a value
Formally, a 5-tuple:
Name and Scope
Identifier rules and significant characters
range of instructions over which variable
name is known
Blocks (as in Pascal or C)
Static vs dynamic scope binding
Consists of
Set of values
Built-in/Primitive vs User-defined types
Implicit declarations
e.g., FORTRAN and first letter of a variable and first
assignment in BASIC or Foxpro
Dynamic typing
Why Use Data Types?
Purpose: classification and protection
note that all data are ultimately represented
as bit-strings
compile-time checking and resolution
explicit specification
Complex Data Types
User-defined enumeration types
Composite types
cartesian product (records or structures)
mapping (arrays)
L-value and r-value
l-value: address/location
memory allocation
r-value: contents/encoded value
* binding
Allocation and de-allocation
referencing (address-of)
Unnamed Variables
e.g., Pascal
Statements and Routines
Expressions and statements
Conditional execution
Parameter Passing
Modules and Program Structure
Expressions and
Operands: variables, literals
Unary, binary, and others (functions?)
Value returned vs effect
The semicolon: C (terminator) vs Pascal (separator)
Blocks: C { } vs Pascal (begin-end)
Control structures: decision, iteration, routines
Conditional Execution
Conditions and boolean values
Relationship of conditions and int in C
Not adopted in Java
If-statements and dangling else
The switch statement
The break; statement
For statement
Loop control variable
The while loop
while vs do-while
do-while versus repeat-until
Iteration using goto
Program unit; sequence of instructions
Also a 5-tuple:
About Routines
Functions vs procedures
Parameter Passing
By value
By reference
Activation Records
Modules and
Program Structure
Programming in the Large
need to compose program through units
program units that interact with each
information hiding
independent modules with interfaces
Interface and Implementation

Programming Paradigms