Unit 1 : Part 1 :Programming paradigms
Introduction to programming paradigms, Introduction
to four main Programming paradigms- procedural,
object oriented, functional, and logic & rule based.
Need of object oriented programming
Functional View of a Computer
Output
CPU Devices
Input
Devices
Main Secondary
Memory Memory
Functional View of a Computer
▪ Humans interact with computers via Input and
E.g., Keyboard Output (IO) devices
and mouse E.g., Monitor
▪ Information from Input devices are processed by
Output
Input the CPU and may be shuffled off to the main or
secondary memory Devices
Devices
▪ When information need to be displayed, the CPU
sends them to one or more Output devices
• A program is just a sequence of instructions telling the computer what
to do
• Obviously, we need to provide these instructions in a language that
computers can understand
• We refer to this kind of a language as a programming language
• Python, Java, C and C++ are examples of programming languages
• Every structure in a programming language has an exact form (i.e.,
syntax) and a precise meaning (i.e., semantic)
Six reasons to Learn Programming Languages
Development of
Early Language
Impact of Programming Paradigms
This Causes Impact on
● Way Programmers are Solving the Program
● Challenge to Describe Needs of the Stakeholders and Solution
Requirements
● Provided an Underlying Model to Verify and Validate the Program in a
Reliable Manner.
● Minimize the Design Errors
● Provides Variety of Techniques to manage Complexity.
● How to Design a Software
Influences in
Design of
Programming
Languages
Programming Paradigms- IMPERATIVE and DECLARATIVE
use mnemonics to represent machine instructions
ØEach statement
● Imperative in assembly
programming: language
telling corresponds to one statement in
the "machine”
(computer)
machine how to do something, and as a result
language.
what you want to happen will happen.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
● Declarative programming: telling the
"machine” (computer) what you would like to
happen, and let the computer figure out how
to do it.
Programming Paradigms- IMPERATIVE and DECLARATIVE
useProblem
mnemonics to represent
Statement machine
:- Double all instructions
the numbers in an array.
ØEach statement in assembly language corresponds to one statement in
machine language.
Imperative style of programming: Declarative style of programming:
var numbers = [1,2,3,4,5]
ØAssembly language programs var
have
numbersthe same
= [1,2,3,4,5] advantages and
var doubled = []
disadvantages as machine language programs.
var doubled = numbers.map(function(n)
for(var i = 0; i < numbers.length; i++) { {
Compare the following machine language and assembly language programs:
var newNumber = numbers[i] * 2 return n * 2
doubled.push(newNumber) })
}
console.write(doubled) //=> [2,4,6,8,10] console.log(doubled) //=> [2,4,6,8,10]
Programming Paradigms- PROCEDURAL/STRUCTURED
use mnemonics to represent machine instructions
● Procedural programming is a computer programming language that organises our code into small
ØEach statement
programs" that usein
andassembly language corresponds to one statement in
change our datas.
machine language.
● Structured programming is a programming paradigm recommending hierarchical division into
blocks of code with one entry point and one or more exit points.
ØAssembly
● In structuredlanguage programs have the same
programming we use three main structures :
advantages and
disadvantages
○ sequences as(instruction
machine_1;language programs.
instruction _2;…; instruction _n
○ choices (if, if...else, switch, case)
Compare the following
○ iterations machine
(while, repeat, for). language and assembly language programs:
● Key words: variables, types, procedures and abstract datas. Using: network systems, operating
systems, etc.
● Procedural/structured languages:
Fortran , Cobol , Pascal, c, ,c++ etc,
Programming Paradigms- PROCEDURAL/STRUCTURED
use mnemonics to represent machine instructions
ØEach statement in assembly language corresponds to one statement in
machine language.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms-Object-oriented programming
● Object-oriented programming is a programming paradigm in which programs are defined using
objects - the state of the connecting elements (or fields) and behavior (or method).
use
● mnemonics to represent
Object-oriented computer programmachine
is expressedinstructions
as a set of such objects, which communicate with
each other in order to perform tasks.
ØEach statement in assembly language corresponds to one statement in
● Key words: classes and objects, inheritance, encapsulation, polymorphism.
machine
● Using:language.
www and stand-alone applications.
● Object-oriented
ØAssembly languages
language programs have the same advantages and
○ Simula,
disadvantages
○ Smalltalk,as machine language programs.
○ C++,
Compare the following machine language and assembly language programs:
○ C#,
○ Java, others.
Programming Paradigms- Object Oriented
use mnemonics to represent machine instructions
ØEach statement in assembly language corresponds to one statement in
machine language.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms-Functional programming
● Functional programming is a programming paradigm in which the functions are the core values
and the emphasis is on valuation (often recursive) function, and not to execute commands.
use●mnemonics to for
Theoretical basis represent machine instructions
functional programming was developed in the 19330s of the Twentieth century
by Alonzo Church's lambda calculus, called lambda calculus with types.
ØEach
● Keystatement in assembly language corresponds to one statement in
words: functions, lambda calculus, parametric polymorphism.
machine language.
● Using: theoretical, in telecommunications, in financial calculations.
● Functional languages:
ØAssembly
○ Lisp,
language programs have the same advantages and
disadvantages
○ ML, as machine language programs.
○ Haskell,
Compare
○ H#,the following machine language and assembly language programs:
○ Erlang
○ others.
Programming Paradigms- Functional Programming
use mnemonics to represent machine instructions
ØEach statement in assembly language corresponds to one statement in
machine language.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms- Functional Programming
use mnemonics to represent machine instructions
ØEach statement in assembly language corresponds to one statement in
machine language.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms-Logical & Rule Based programming
• The paradigm of logic programming is a programming method in which the program is given
as a set of relations, and the relationship between these dependencies.
• Key words: facts, reports, queries.
• Using: theoretical, artificial intelligence.
use• mnemonics to represent machine instructions
Logical languages:
ØEach • statement
Gödel, in assembly language corresponds to one statement in
• Fril,
machine• language.
Prolog, others.
ØAssembly language programs have the same advantages and
disadvantages as machine language programs.
Compare the following machine language and assembly language programs:
Programming Paradigms- Logical programming
use mnemonics to represent machine
instructions
ØEach statement in assembly language
corresponds to one statement in machine
language.
ØAssembly language programs have the same
advantages and disadvantages as machine :
Programming Paradigms- Logical programming
use mnemonics to represent machine
instructions
ØEach statement in assembly language
corresponds to one statement in machine
language.
ØAssembly language programs have the same
advantages and disadvantages as machine :
Procedure Object Oriented Function Oriented Logic Oriented
C C++ ML PROLOG
COBOL Java LISP CURRY
FORTRAN Ruby DART FRIL
PASCAL Python SCHEME OZ
Java Script Ada LOGO ALMA-0
Smalltalk
SQL
PhP
Need of object oriented programming
1. Code Organization and Reusability: OOP allows developers to organize code
into reusable objects.
2. Modularity and Scalability: OOP promotes modularity, breaking down complex
systems into smaller, manageable components.
3. Encapsulation and Data Security: OOP emphasizes encapsulation, which
means that objects contain both data (attributes) and methods (behaviors).
Need of object oriented programming
4. Inheritance and Code Reuse: OOP supports inheritance, where new classes
can inherit properties and behaviors from existing classes.
5. Collaboration and Teamwork: OOP enables effective collaboration among
software development teams.
6. Real-World Modeling: OOP closely aligns with real-world concepts, making it
easier to model and represent real-world entities and their relationships in
code.