Programming Paradigms
Lecture - Basics of Programming Paradigms and their types
Lecture by
G.Madhupriya
Assoc. Prof.,
Dept. of CSE,
TCE.
gmadhupriya@tce.edu
CO2 - Solve engineering problems using imperative paradigm based
sequential programming.
Programming Paradigms
• A programming paradigm is a style or way or model of
programming
• It is a way to classify programming languages based on their
feature
• There are many programming languages. Each has its own
strategy (methodology) when it is implemented. That strategy
is what known as paradigms
• Generally it is of two types
• Imperative Programming Paradigm
• Declarative Programming Paradigm
Imperative Programming Paradigms
• This paradigm is the oldest paradigm
• It defines explicitly what goal has to be achieved and how the
goal has to be achieved.
• It is a paradigm of building programs expressing the logic of
computation with the control flow logic
• It is the oldest paradigm that is based on Von Neumann
architecture.
Imperative Programming Paradigms
Declarative Programming Paradigms
• States the goal to be achieved explicitly
• The procedure of how to achieve is not given explicitly
• a style of building programs that expresses logic of
computation without talking about its control flow
• therefore it considers programs as theories of some logic
(Mathematics / Data / Known facts)
Declarative Programming Paradigms
What Makes a Language Imperative?
• Programs written in imperative programming languages consist of
• A program state
• Instructions that change the program state
• Program instructions are “imperative” in the grammatical sense of
imperative verbs that express a command
• Commands in an imperative language are similar to the native
machine instructions of traditional computer hardware – the von
Neumann-Eckley model.
• John von Neumann: first person to document the basic concepts of
stored program computers.
The “von Neumann” Computer
• A memory unit: able to store both data and instructions
• Random access
• Internally, data and instructions are stored in the same
address space & and are indistinguishable
• A calculating unit (the ALU)
• A control unit, (the CPU)
Stored program → an instruction set
• Duality of instructions and data → programs can be self
modifying
Turing Completeness
• Alan Turing: A British mathematician, logician, and eventually
computer scientist.
• A language is Turing complete if it can be used to implement
any algorithm and perform that computation.
• Central to the study of computability
Imperative Programming
• Imperative languages are Turing complete if they support data structures
representation of data (eg.integers), basic arithmetic operators,
expressions with assignment, sequencing, looping and branching etc.
• Modern imperative languages generally also include features such as
– Expressions and assignment statements
– Control structures (loops, decisions)
– I/O commands
– Procedures and functions
– Error and exception handling
– Library support for data structures
History of Imperative Languages
• First imperative languages: Assembly Level Language
• 1954-1955: Fortran (FORmula TRANslator)
John Backus developed for IBM 704
• Late 1950’s: Algol (ALGOrithmic Language)
• 1958: Cobol (COmmon Business Oriented Language) Developed
by a government committee ( Grace Hopper)
• Pascal
• C, C++, Java, Ada………..
Imperative Programming Paradigms
• This paradigm is the oldest paradigm
• It defines explicitly what goal has to be achieved and how the
goal has to be achieved explicitly
• It is the oldest paradigm that is based on Von Neumann
architecture of stored program concept in the basic computer
system with memory unit, calculating unit (ALU) and control
(CPU) unit
• Imperative Languages are Turing Complete programming
languages with the capability to implement the algorithm
with initial program state and commands/ statement of the
instruction set that change the state and achieve the output of
the algorithm using computations
• Two main design principles of imperative paradigms are
Structured programming and Efficiency.
Imperative Programming Paradigms
• From the definition it is clear that the step by step approach to
achieve the goal gives the paradigm a structured design with
the controlled flow of execution between the single entry and
single exit.
• The controlled execution structure is evident from the
syntactic control flow of statements defined by the imperative
programming languages.
• Using the structured syntactic control flow execution, the user
is able to interact directly with the assignment oriented
computer system and get their task completed by the step –
wise computation - Efficiency
• C, C++, Java, Fortran, Pascal, Basic, Algol, Ada, C# etc.
Features of Imperative Languages
• Statements are commands
– Command order is critical to correct execution;
– Programmers control all aspects: algorithm specification,
memory management, variable declarations, etc
• They work by modifying program state
• Statements reflect machine language instructions.
• Statements represent the structured flow of imperative
programs.
• Statements represent the sequential flow or non sequential
flow of instructions.
• Non sequential flow leads to the design of branching and
looping control statements.
Features (Contd…..)
• They are usually "typed“ either statically or dynamically.
– Basic data types (e.g.,int, float, boolean, char)
– Compound data types (structs, arrays).
• Statement types:
– Expression, Declarations and control flow statements
– Expression statements include assignment statements
– Control flow statements - condition statements and looping
statements
• I/O and error handling mechanisms.
• A method of grouping all of the above into a complete program -
(program composition).
– Procedural abstraction, step-wise refinement, function
mechanisms.
Expressions and Assignment
• imperative languages operate by changing program state.
This is done using destructive assignment statements.
• General format:
target = expression
• Assignment operators: = or :=
• Expressions represent a value and have a type.
• Understanding expressions means understanding operator
precedence, operator overloading, casting and type conversion,
among other issues.
• Machine language supports data types indirectly through different
instructions:
integer add/sub/mul/div
versus
floating point add/sub/mul/div, for example.
• Internally, no visible way to distinguish integers from floats from
characters.
– Languages from Fortran on have provided some protection from
type errors, and some ability to define new types.
Assignment Semantics
• Evaluate expression to get a single value
• Copy the expression value to the target.
• Pure imperative programs implement copy semantics (as
opposed to the reference semantics used in object-oriented
languages)
Procedural Programming
• Nicholas Wirth described imperative programs as being
“algorithms plus data structures”.
• Algorithms become programs through the process of
procedural programming and stepwise refinement.
• Imperative programming + procedures = procedural
programming.
• Libraries of reusable functions support the process (functions
= procedures)
• Procedural programming used in the form of interfaces known
as Procedural Abstraction
Procedural Abstraction
• Procedural abstraction allows the programmer to be
concerned mainly with the interface between the function
(procedure) and what it computes, ignoring the details of how
the computation is accomplished.
• Abstraction allows us to think about what is being done, not
how it is implemented.
Stepwise Refinement
• Stepwise refinement (also called functional decomposition)
uses procedural abstraction by developing an algorithm from
its most general form [the abstraction] into a specific
implementation.
• Programmers start with a description of what the program
should do, including I/O, and repeatedly break the problem
into smaller parts, until the sub-problems can be expressed in
terms of the primitive states and data types in the language.
Thank You