MAJOR PROGRAMMING
PARADIGMS
MUHAMMED ASIM YILDIZ
Inside
 What is Programming Paradigms?
 Imperative vs Declarative Programming Paradigms
 4 Major Programming Paradigms
 Procedural Programming Paradigm
 Logical Programming Paradigm
 Functional Programming Paradigm
 Object Oriented Programming Paradigm
Programming Paradigm
 Is an approach to programming a computer;
 Based on mathematical theory or
 A coherent set of principles
Imperative – Declarative Programming
Paradigms
 Question :
 I’m right next to Eagle Statue. How do I get to Digiturk from here?
 How can we define it with Imperative PP?
 How can we define it with Declarative PP?
Imperative Way
 Head east on Mumcu Bakkal Sokağı toward Şht. Asım Cd.
 Turn left onto Şht. Asım Cd.
 Continue onto Masuklar Ykş. (110m)
 Continue onto Yıldız Cd. (270m)
 Digiturk is on the right
Declarative Way
 Digiturk’s address is Cihannüma, Yıldız Cd., 34353 Beşiktaş/İstanbul
Imperative programming is like how you do something,
while declarative programming is more like what you do.
Another Example
 You go to a restaurant and approach the front desk
 If you say :
 I see that table located under the TV is empty
 I would like to sit there
 IMPERATIVE (define how to get a table)
 Or if you say :
 Table for one, please
 DECLARATIVE (what you want)
Many (if not all) declarative approaches
have some sort of underlying imperative abstraction.
Imperative-Declarative Relation
 The declarative response for restaurant assumes that the front-desk guy knows..
 Knowing the Digiturk address assumes you have a some sort of GPS that knows..
 ‘THE IMPERATIVE STEPS’
Examples of PP with
Programming Languages
 SQL :
 HTML :
<article>
<header>
<h1>Declarative Programming</h1>
<p>Sprinkle Declarative in your verbiage to sound smart</p>
</header>
</article>
SELECT * FROM Users WHERE Country=’Mexico’;
Examples of PP with
Programming Languages
 Javascript (write a function called double which takes an array, and return a new array where
the values doubled) :
function double (arr) {
let results = []
for (let i = 0; i < arr.length; i++){
results.push(arr[i] * 2)
}
return results
}
function double (arr) {
return arr.map((item) => item * 2)
}
Programming Languages by Paradigms
 Imperative: C, C++, Java
 Declarative: SQL, HTML
 (Can Be) Mix: JavaScript, C#, Python
4 Major Programming Paradigms
 Imperative
 Procedural
 Object-Oriented
 Declarative
 Logical
 Functional
IMPERATIVE PROGRAMMING PARADIGMS
Procedural Programming Paradigm
 The entire program is a single algorithm consists of independent modules
 The complete functionality written linearly (step-by-step)
Procedural PP Example
Procedural PP Advantages
 Efficient (modules are easier to write)
 Close to the machine
 Best for expressing algorithms
Procedural PP Disadvantages
 The semantics of the program can be complex
 Hard to understand and hard to prove (lots of modules)
 Side effects make debugging harder
 Order is crucial (step-by-step)
Object Oriented Programming Paradigm
 Real-world objects are each viewed as seperate entities
 Each object has it’s own state which is modified only by built in methods
 Objects operated independently (communication is done by message passing)
OOP PP Example
OOP PP Advantages
 Inheritance (reusable code and code extensibility)
 Changing code without the need to change existing code (subclass)
 Encapsulation and information hiding
 Prevents data from being accessed by the code outside
 Define data as private and open them to outside by public methods
 Parallel code development with big teams
 More human-friendly and readable code
OOP PP Disadvantages
 First time coding can be more extensive (code duplication)
 Can create a massive amount of unnecessary code
 Can be slow because of the overhead (negligible)
DECLARATIVE PROGRAMMING PARADIGMS
Logical Programming Paradigm
 Execution of a logic program is a theorem proving process (Datalog, Prolog)
 Program statements express facts, rules and predicates
 It consists from a system of formal logic
Logical PP Example
 Given information about fatherhood and motherhood, determine grand parent relationship :
 Given the information called facts;
 John is father of Lily – father(john, lily)
 Kathy is mother of Lily – mother(kathy, lily)
 Lily is mother of Bill – mother(lily, bill)
 Ken is father of Karen – father(ken, karen)
 Who are grand parents of Bill?
 grandparent(X,Z) :- parent(X,Y), parent(Y,Z)
 parent(X,Y) :-father(X,Y)
 parent(X,Y) :-mother(X,Y).
Logical PP Advantages
 The system solves the problem
 Programming steps are kept to a minimum
 Proving the validity of the program is simple
Logical PP Disadvantages
 Not efficient as other programming paradigms
 Takes too much effort to create a program
 Not widely used (medical diagnosis, robot control etc.)
Functional Programming Paradigm
 Views all subprograms as functions (in mathematical sense)
 Functions take in arguments and return a single solution
 Solution returned is based entirely on the input
 The time which a function is called has no revelance
Functional PP Example
Functional PP Advantages
 High level of abstraction
 Functions suppress many of the programming details
 Removes the possibility of making too many errors (simple)
 Good candidates for programming to parallel computers
Functional PP Disadvantages
 Problems involving many variables or
 Problems with a lot of sequential code runs;
 Sometimes easier to implement with Object oriented programming
THANK YOU

Major Programming Paradigms

  • 1.
  • 2.
    Inside  What isProgramming Paradigms?  Imperative vs Declarative Programming Paradigms  4 Major Programming Paradigms  Procedural Programming Paradigm  Logical Programming Paradigm  Functional Programming Paradigm  Object Oriented Programming Paradigm
  • 3.
    Programming Paradigm  Isan approach to programming a computer;  Based on mathematical theory or  A coherent set of principles
  • 4.
    Imperative – DeclarativeProgramming Paradigms  Question :  I’m right next to Eagle Statue. How do I get to Digiturk from here?  How can we define it with Imperative PP?  How can we define it with Declarative PP?
  • 5.
    Imperative Way  Headeast on Mumcu Bakkal Sokağı toward Şht. Asım Cd.  Turn left onto Şht. Asım Cd.  Continue onto Masuklar Ykş. (110m)  Continue onto Yıldız Cd. (270m)  Digiturk is on the right
  • 6.
    Declarative Way  Digiturk’saddress is Cihannüma, Yıldız Cd., 34353 Beşiktaş/İstanbul
  • 7.
    Imperative programming islike how you do something, while declarative programming is more like what you do.
  • 8.
    Another Example  Yougo to a restaurant and approach the front desk  If you say :  I see that table located under the TV is empty  I would like to sit there  IMPERATIVE (define how to get a table)  Or if you say :  Table for one, please  DECLARATIVE (what you want)
  • 9.
    Many (if notall) declarative approaches have some sort of underlying imperative abstraction.
  • 10.
    Imperative-Declarative Relation  Thedeclarative response for restaurant assumes that the front-desk guy knows..  Knowing the Digiturk address assumes you have a some sort of GPS that knows..  ‘THE IMPERATIVE STEPS’
  • 11.
    Examples of PPwith Programming Languages  SQL :  HTML : <article> <header> <h1>Declarative Programming</h1> <p>Sprinkle Declarative in your verbiage to sound smart</p> </header> </article> SELECT * FROM Users WHERE Country=’Mexico’;
  • 12.
    Examples of PPwith Programming Languages  Javascript (write a function called double which takes an array, and return a new array where the values doubled) : function double (arr) { let results = [] for (let i = 0; i < arr.length; i++){ results.push(arr[i] * 2) } return results } function double (arr) { return arr.map((item) => item * 2) }
  • 13.
    Programming Languages byParadigms  Imperative: C, C++, Java  Declarative: SQL, HTML  (Can Be) Mix: JavaScript, C#, Python
  • 14.
    4 Major ProgrammingParadigms  Imperative  Procedural  Object-Oriented  Declarative  Logical  Functional
  • 15.
  • 16.
    Procedural Programming Paradigm The entire program is a single algorithm consists of independent modules  The complete functionality written linearly (step-by-step)
  • 17.
  • 18.
    Procedural PP Advantages Efficient (modules are easier to write)  Close to the machine  Best for expressing algorithms
  • 19.
    Procedural PP Disadvantages The semantics of the program can be complex  Hard to understand and hard to prove (lots of modules)  Side effects make debugging harder  Order is crucial (step-by-step)
  • 20.
    Object Oriented ProgrammingParadigm  Real-world objects are each viewed as seperate entities  Each object has it’s own state which is modified only by built in methods  Objects operated independently (communication is done by message passing)
  • 21.
  • 22.
    OOP PP Advantages Inheritance (reusable code and code extensibility)  Changing code without the need to change existing code (subclass)  Encapsulation and information hiding  Prevents data from being accessed by the code outside  Define data as private and open them to outside by public methods  Parallel code development with big teams  More human-friendly and readable code
  • 23.
    OOP PP Disadvantages First time coding can be more extensive (code duplication)  Can create a massive amount of unnecessary code  Can be slow because of the overhead (negligible)
  • 24.
  • 25.
    Logical Programming Paradigm Execution of a logic program is a theorem proving process (Datalog, Prolog)  Program statements express facts, rules and predicates  It consists from a system of formal logic
  • 26.
    Logical PP Example Given information about fatherhood and motherhood, determine grand parent relationship :  Given the information called facts;  John is father of Lily – father(john, lily)  Kathy is mother of Lily – mother(kathy, lily)  Lily is mother of Bill – mother(lily, bill)  Ken is father of Karen – father(ken, karen)  Who are grand parents of Bill?  grandparent(X,Z) :- parent(X,Y), parent(Y,Z)  parent(X,Y) :-father(X,Y)  parent(X,Y) :-mother(X,Y).
  • 27.
    Logical PP Advantages The system solves the problem  Programming steps are kept to a minimum  Proving the validity of the program is simple
  • 28.
    Logical PP Disadvantages Not efficient as other programming paradigms  Takes too much effort to create a program  Not widely used (medical diagnosis, robot control etc.)
  • 29.
    Functional Programming Paradigm Views all subprograms as functions (in mathematical sense)  Functions take in arguments and return a single solution  Solution returned is based entirely on the input  The time which a function is called has no revelance
  • 30.
  • 31.
    Functional PP Advantages High level of abstraction  Functions suppress many of the programming details  Removes the possibility of making too many errors (simple)  Good candidates for programming to parallel computers
  • 32.
    Functional PP Disadvantages Problems involving many variables or  Problems with a lot of sequential code runs;  Sometimes easier to implement with Object oriented programming
  • 33.