Students are expected to understand the term and
meaning behind programming paradigms
Students should be able to demonstrate their
understanding of the most common programming paradigms
in their programming lab activities
Programming Paradigms
Programming Paradigms (1)
Different styles in which a program (or programming
language) can be organised
It consists of certain structures, features and
opinions on how common programming problems can be
solved
There are many paradigms, with each being better
suited for a given type of problem
different paradigms may be used for different
projects etc
Paradigms are not a language or a
tool
you do not build anything with a paradigm
they are more akin to a set of ideals and
guidelines
Paradigms are not mutually exclusive
i.e. some languages may use more than one
paradigm
Programming Paradigms (2)
Programming
Languages and Programming Paradigms
Programming languages are generally not tied to a
specific paradigm
Some have been built with certain paradigms in mind
e.g. Haskel and functional programming
There are languages with a “multi-paradigm” approach
code can be adapted to fit one paradigm or
another
e.g. JavaScript and Python
Programming Paradigms (3)
Types of
Programming Paradigms
There are two types of paradigms:
Imperative
Declarative
Each paradigm depends upon the:
programming language features
style of organising the sourcecode
Imperative Paradigms
Imperative Paradigms (1)
This is a command-driven paradigm
The programming language directs the program
execution
executed as a sequence of statements,
one-by-one
Consists of a set of program statements
each statement will direct the computer to perform a
specific task
The programmer elaborates each statement in detail,
here each statement directs the following:
what needs to be done?
how will it be done?
Examples of imperative paradigm programming
languages:
e.g. Fortran, Pascal and Basic
There are several types of imperative paradigms:
Procedural Programming
Object-Oriented Programming
Parallel Processing Approach
sum = 0
sum += 1
sum += 2
sum += 3
sum += 4
sum += 5
The sum is: 15
Imperative Paradigms (2)
Procedural
Programming
Allows the splitting of instructions into
procedures
Procedures are not functions
functions return a value, whereas procedures do
not
The primary purpose is to accomplish a given task
intended to cause a desired side
effect
Examples of procedural paradigm programming
languages:
e.g. C, C++, Java and Pascal
Advantages of procedural programming are:
code is compact and reusable
breaks problems into smaller problems
utilises CPU storage effectively
sum = 0
for i in range(1, 6):
sum += i
The sum is: 15
Imperative Paradigms (3)
Object-Oriented
Programming
A common paradigm approach often used in
programming
It consists of unique advantages, such as modularity
of the code
Key characteristics of this approach are:
classes, abstraction, encapsulation, inheritance and
polymorphism
An object is an instance of a class
The object will consist of:
attributes/states: the data
associated with the object
methods/behaviours: the
actions/functions that the object can perform
Examples of object-oriented paradigm programming
languages:
e.g. C++, Java, Ruby, and Python
class Calculator:
def __init__(self, n):
self.n = n
self.__sum = 0
def add_numbers(self):
for i in range(0, self.n + 1):
self.__sum += i
return self.__sum
The sum is: 15
Imperative Paradigms (4)
Parallel
Processing Approach
Concerned with processing of the instructions across
multiple processors
Implies basic assumptions about the fundamental
hardware components
i.e. how are the processors and memory connected to
one another?