1 of 19

Programming Paradigms

Kaustubh Kulkarni Assistant Professor,

Department of Computer Engineering, KJSCE.

2 of 19

A programming paradigm is a style, or “way,” of programming.

2

3 of 19

Unstructured (Imperative) Programming

3

  • Consists of only one main program.
  • Here “main program” is a sequence of commands or statements which modify data which is global throughout the whole program.
  • This programming techniques provide tremendous disadvantages once the program gets sufficiently large.
  • No reusability

4 of 19

Example (BASIC language)

5 of 19

Structured Programming

5

  • Structured programming is a kind of imperative programming where control flow is defined by nested loops, conditionals, and subroutines, rather than via gotos.
  • Variables are generally local to blocks (have lexical scope).
  • Early languages emphasizing structured programming: Algol 60, PL/I, Algol 68, Pascal, C, Ada 83, Modula, Modula-2.
  • Structured programming as a discipline is sometimes thought to have been started by a famous letter by Edsger Dijkstra entitled Go to Statement Considered Harmful.

6 of 19

Example of an unstructured paradigm

7 of 19

Example of structured paradigm

8 of 19

Procedural Programming

  • With procedural programming you can combine repeating sequences of statements into one single entity called a procedure
  • A procedure call is used to invoke the procedure.
  • The main program coordinates calls to procedures and hands over appropriate data as parameters.
  • After sequence of statements inside the procedure has been completed, the flow of control proceeds right after the position where the call was made.
  • Code reuse is possible.
  • Programs can now be written in a more structured and error free manner.
  • For example, if a procedure is correct, every time it is used it produces correct results.
  • Consequently, in cases of errors you can narrow your search to those places which are not proven to be correct.

8

9 of 19

9

Procedural Programming Illustration 1

10 of 19

10

Procedural Programming Illustration 2

11 of 19

Example of procedural paradigm

12 of 19

Modular Programming

12

  • With modular programming procedures of a common functionality are grouped together into separate modules.
  • A program therefore no longer consists of only one single part.
  • It is now divided into several smaller parts which interact through procedure calls and which form the whole program.
  • The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters.
  • Each module can have its own data. This allows each module to manage an interna state which is modified by calls to procedures of this module. However, there is only one state per module and each module exists at most once in the whole program.

13 of 19

13

Modular Programming Illustration

14 of 19

Object-Oriented Programming (OOP)

  • Organizing code around objects that represent real-world entities or concepts.
  • These objects have data (attributes) and behaviors (methods) that operate on that data.
  • Code is organized into classes that define the blueprint for objects and their behavior.
  • Objects are instances of classes.
  • Data is encapsulated within objects, protecting it from unauthorized access and modification.
  • Inheritance allows existing code to be reused and extended for new objects.
  • Encapsulation and interfaces further promote reusability.

15 of 19

Example : Procedural

16 of 19

Example : Modular

Header file : area_calculations.h

17 of 19

Example : Modular

18 of 19

Example of OOP

19 of 19

Feature

Procedural Programming

Modular Programming

Object-Oriented Programming (OOP)

Focus

Program logic flow

Code reusability

Real-world entities and their behavior

Structure

Linear sequence of functions

Independent modules

Classes and objects

Data Organization

Less emphasis on encapsulation

Data encapsulation within modules

Data encapsulated within objects

Code Reusability

Limited

High emphasis

High emphasis, with inheritance