0% found this document useful (0 votes)
2 views

Programming Paradigms

The document outlines various programming paradigms including procedural, object-oriented, event-driven, declarative, logic, and functional programming. It explains the characteristics and relationships between these paradigms and provides insights into Integrated Development Environments (IDEs) and their features. Additionally, it discusses the creation of event-driven programs and highlights trends in programming languages that incorporate multiple paradigms.

Uploaded by

mohsulai2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programming Paradigms

The document outlines various programming paradigms including procedural, object-oriented, event-driven, declarative, logic, and functional programming. It explains the characteristics and relationships between these paradigms and provides insights into Integrated Development Environments (IDEs) and their features. Additionally, it discusses the creation of event-driven programs and highlights trends in programming languages that incorporate multiple paradigms.

Uploaded by

mohsulai2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

UNIT1 - Programming

Week [10] –Programming Paradigms

1
Lesson Learning Outcome
Pass Merit Distinction

LO2 Explain the characteristics of procedural, object-


oriented and event driven programming, conduct an
analysis of a suitable Integrated Development Environment
(IDE)

P2 Give explanations of what M2 Analyse the common D2 Critically evaluate the


procedural, object-oriented features that a developer has source code of an
event driven paradigms are; access to in an IDE. application which
their characteristics and implements the program
relationship between them. paradigms, in terms of the
code structure and
characteristics.

2
What is a Programming Paradigm?

▪ Programming paradigm is a style of programming which has characteristic


features.
▪ One can say these are the foundations on which programming languages are
designed and implemented.
▪ Some languages can be classified into multiple paradigms.
▪ Some paradigms are concerned mainly based on execution model of the
language.
▪ Other paradigms are concerned mainly with the way that code is organized.
▪ Yet others are concerned mainly with the style of syntax and grammar.

3
Common Programming Paradigms

Imperative Programming (Procedural Paradigm)

Object Oriented Programming

Event Driven Programming

Declarative Programming

Logic Programming

Functional Programming

4
Imperative Programming

▪ Imperative = Procedural = Structured Programming


▪ Computer use reusable memory
▪ Programs runs by changing the state of the machine via Assignment
▪ Control flow is explicit, uses Sequence, Selection, Repetition
▪ These can be more efficiently translated to machine language
▪ Structured Programming is a refined imperative style with 2 added
features
▪ No GOTOs Fortran, Algol,
▪ Variables have lexical scope due to modules Pascal, Basic, C

5
Object Oriented Programming

▪ Programs are represented as a Group of Objects.


▪ Objects exhibit their own behaviour.
▪ In imperative style Data are Passive, Procedures are Active.
▪ O-O paradigm, data is combined with procedures to give objects.
For example in the imperative paradigm, one would write a procedure which prints the various
kinds of object in the program. In the O-O paradigm, each object has a print-method, and you "tell"
an object to print itself.

▪ Objects are grouped in Classes.


Simula 67, Smalltalk, java, C++,
▪ Classes are arranged in a Hierarchy – C# , Modula 3, Ruby, Python
Sub classes inherit features from Super classes

6
Declarative Programming

▪ Also called Non Imperative or SELECT Name, Salary


Non Procedural FROM Employee
WHERE DepName = ‘Sales’
▪ Control Flow is implicit
ORDER BY Salary DESC
▪ Programmer states only what the
result should look like, not how to No Loops
obtain it. No Selections
▪ SQL – Structured Query Language No Assignments
is good example for this NO ALGORITHMS

7
Logic Programming

▪ This is also Declarative Programming


▪ What is known about the domain is defined as
▪ Facts
▪ Inference Rules
▪ Solution is found by the Interpreter by
▪ Unification – Principle of substitution
▪ Backtracking – Return to prior step and continue

8
PROLOG - Example
/* Some rules */`
is_digesting(X,Y) :- just_ate(X,Y).
is_digesting(X,Y) :- just_ate(X,Z), is_digesting(Z,Y).
/* Some facts */
just_ate(mosquito,blood(john)).
just_ate(frog,mosquito).
just_ate(stork,frog).

? is_digesting (Who, mosquito)


Who = frog
Who = stork

9
Functional Programming

▪ This is also Declarative Programming


▪ No Variables and therefore No States
▪ Everything is defined as Functions
▪ No state changes – Immutable
▪ Thus preserve Referential Transparency – Guarantees
that a function return the same result for the same
parameters in each and every call,
▪ LISP and Haskel are functional language examples.

10
Event-driven Programming

Event-driven programming is a
programming paradigm in which
the flow of program execution is
determined by events - for
example a user action such as a
mouse click, key press, or a
message from the operating
system or another program.

11
Key Terminology

The event source is an This provides The listener is in effect A collection of routines
object on which the information of the a loop which waits for that defines the
event occurs. Source occurred event. an event to occur. responses to the
provides information Event(S). In some
of the occurred event implementations
to it's handler via an Listener and Handler is
Event object. the same

12
How to create an Event-driven Program

▪ Step 1: The first step in developing an event-driven


program is to write a series of subroutines, or methods,
called event-handler routines.
▪ Step 2: The second step is to bind event handlers to
events so that the correct function is called when the event
takes place.
Graphical editors combine the first two steps: double-click on a
button, and the editor creates an (empty) event handler

13
How to create an Event-driven Program

▪ Step 3: Final step is to write the main loop. Most event-


driven programming environments already provide this
main loop, so it need not be specifically provided by the
application programmer.

14
New Trends in Languages

▪ Based on the main features we call it an Imperative, Object Oriented or


Functional language.
▪ Very few languages implement a paradigm 100%. When they do, they are
pure.
▪ It is incredibly rare to have a “pure OOP” language or a “pure functional”
language.
▪ A lot of languages will facilitate programming in one or more paradigms.

▪ In Scala you can do imperative, object-oriented, and functional


programming quite easily

15
Lesson Summary

▪ What is a Programming Paradigm


▪ Common Programming Paradigms
▪ Imperative Programming
▪ Object Oriented Programming
▪ Declarative / Logic Programming
▪ Functional Programming
▪ Event-driven Programming
▪ New trends in languages

16

You might also like