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

Lec2-Programming-Paradigms

The document outlines various programming paradigms, primarily focusing on imperative and declarative styles. It details the characteristics and advantages of imperative paradigms such as structured, procedural, and object-oriented programming, as well as declarative paradigms like functional and logical programming. Each paradigm is described in terms of its approach to problem-solving and code organization, highlighting key concepts such as assignment statements, global variables, and object-oriented principles like inheritance and polymorphism.

Uploaded by

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

Lec2-Programming-Paradigms

The document outlines various programming paradigms, primarily focusing on imperative and declarative styles. It details the characteristics and advantages of imperative paradigms such as structured, procedural, and object-oriented programming, as well as declarative paradigms like functional and logical programming. Each paradigm is described in terms of its approach to problem-solving and code organization, highlighting key concepts such as assignment statements, global variables, and object-oriented principles like inheritance and polymorphism.

Uploaded by

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

PROGRAMMING

PARADIGMS
ITP 224: INTEGRATIVE PROGRAMMING AND TECHNOLOGIES 1
LECTURE 2
ELMER H. FESTIJO – INSTRUCTOR 1
WHAT IS A PROGRAMMING PARADIGM?

 is a style, technique, or way of writing a


program.
 are the various approaches to solve a
problem.

 Two primary programming paradigms


an imperative
a declarative
IMPERATIVE PARADIGM:

 The imperative style of programming


emphasis on explicit control f low, it means
the order in which statements, instructions, or
function calls are executed.
 The main characteristics of the Imperative
s ty l e of p r og ra m m i ng a r e a s s i g nm ent
statements and global variables.
ASSIGNMENT STATEMENTS:
 I m p e ra ti v e p r o g ra m m i n g s ty l e u s e s
statements that change a program’s state.
The program state is nothing but the contents
of the memory at a particular time.
 In computer programming, an assignment
statement sets or re-sets the value stored in
the storage location(s) denoted by a variable
name.
ASSIGNMENT STATEMENTS:

Example:
GLOBAL VARIABLE:
 A global variable is a
variable with global
scope. Scope refers to
the visibility of
variables. By global
scope, it means the
variable is visible and
accessible throughout
the program.
DECLARATIVE PARADIGM
 Declarative paradigm is a non-imperative
style of programming. In the declarative
programming paradigm, we only tell the
computer what the problem is and let the
system decide what steps to take and also
the sequence of those steps.
 Imperative says how to do it, and declarative
says what to do.
DECLARATIVE PARADIGM

 There are several


paradigms and
languages which are
i n f lu e n c e d b y t h e
declarative paradigm,
such as a Functional
P arad i g m , L og i cal
Paradigm, and
Database.
IMPERATIVE PARADIGMS

 Following are the few paradigms which are


influenced by the imperative paradigms

1. Structured Paradigm
2. Procedural Paradigm
3. Object-Oriented Paradigm
STRUCTURED PROGRAMMING:
 Structured programming is a programming
paradigm that uses structured control f low to
improve code clarity and quality.
 Three ways of com b i ni ng p rog ram s -
sequencing, selection, and iteration.
STRUCTURED PROGRAMMING:
ADVANTAGES OF STRUCTURED
PROGRAMMING:
 The code is well organized.
 We can execute a block of code repeatedly
till the given conditions match.
 Improved decision making power. Based on
some conditions, we can decide to execute or
not any block of code.
 The structured f lo w of execution using
if/else and for/while.
PROCEDURAL PROGRAMMING:
 A procedural programming paradigm is
derived from structured programming. It is
based on the concept of the procedure call.
Procedures are also known as routines,
subroutines, methods, or functions.
 A Procedure contains a series of
instructions coupled together.
PROCEDURAL PROGRAMMING:
PROCEDURAL PROGRAMMING:
 Examples of procedural languages are C,
C + + , J a v a , K o t l i n , P H P, e t c . a s t h e s e
languages suppor t functions, methods,
procedures.
PROCEDURAL PROGRAMMING:
 Advantages:
The code becomes reusable.
Writing modular code is possible; this
gave birth to another paradigm that is
Modular Programming.
It is easier to keep track of the control
flow.
OBJECT-ORIENTED PROGRAMMING:
 An object-oriented programming paradigm
is based on the concept of objects. An object
can be any real-world entity. An object has
data(properties, variables) and behaviour
(methods).
 Object-Oriented paradigm took
programming to the next level by supporting
features like abstraction, encapsulation,
inheritance, polymorphism.
CLASS-BASED:
 In class-based
languages, the
classes are def ined
beforehand, and the
ob j ec ts a r e
instantiated based
 In c la s s - b a s ed la ng u a g es , o b j ec t s a re
on the classes.
instances of classes. Java supports class-
based programming.
PROTOTYPE-BASED:

 In prototype-based languages, the


objects are the primary entities, and class
doesn’t exist in it. We create new objects
based on the already existing objects.
PROTOTYPE-BASED:
ADVANTAGES OF OBJECT-ORIENTED
PROGRAMMING:
 Abstraction: hide the implementation
details. Generally, abstraction is achieved
through abstract classes and interfaces.
 Encapsulation: It is about wrapping the
implementation (code) and the data it
manipulates (variables) within the same
class. It is achieved using access modif iers
like public, private, and protected.
ADVANTAGES OF OBJECT-ORIENTED
PROGRAMMING:
 Inheritance: It is a way of creating a new class(child)
from the existing class(base or parent). This
mechanism enables the code reusability. As a
derived class gets all the features of the base class,
and it also allows to extend the functionality of a
base class without modifying the existing source
code.
 Polymorphism: We can have a method which has
different behaviours based on the context in which it
i s u s e d . We c a n a c h i e v e t h i s u s i n g m e t h o d
overloading and method overriding.
DECLARATIVE PARADIGMS

 Following are the list of some paradigms


which are inf lu enced by the declarative
paradigms:
1. Functional Paradigm
2. Logical Paradigm
FUNCTIONAL PROGRAMMING:

The principles of modularity and code reuse in


functional programming are the same as in
procedural programming since they both stem
from structured programming. For example,
Procedures resemble functions. Both allow the
reuse of the same code in various parts of the
programs.
FUNCTIONAL PROGRAMMING:
The benef it of this approach is, No assignment
operator = No changing the value of variables = No
side effect.
 Instead of assigning values to variables, we pass
those values as input arguments to the same or
other functions.
 No side effect means the function doesn’t change
the value of any variable, which is outside of its
scope.
FUNCTIONAL PROGRAMMING:
FUNCTIONAL PROGRAMMING:
FEATURES OF FUNCTIONAL
PROGRAMMING:
 Higher-order functions
 First-class functions
 Recursion
 Lazy evaluation
 Referential transparency
LOGICAL PROGRAMMING:
In the Logical style of programming, f ir st, we
def in e some known facts and rules to make
computers aware of the problem domain. Then,
when we ask queries to a computer, it makes
some logical deduction based on the initially
given facts and rules, and returns a solution to
our problem.
If x is a bird or an airplane, then x has wings.
Tweety is a bird.
Does Tweety have wings? y/n?, true or false?

You might also like