✍️ Get Writing Help
WhatsApp

Overview of Programming Paradigms

1
Overview of
Programming
Paradigms
Week 6
2
Overview of Programming Paradigms
 Lecture Objectives:
 Be able to explain the differences between programming languages and programming paradigms.
 Be able to differentiate between low-level and high-level programming languages and their
associated advantages and disadvantages
 Be able to list four programming paradigms and describe their strengths and weaknesses.
 Introduction to Computer Programming
 Programming Languages
 Programming Paradigms
 Exercises
3
Programming Languages
 A computer program is a clear, step-by-step, finite set of instructions. A
computer program must be clear so that only one meaning can be derived
from it and is written in a computer language called a programming
language.
 There are three categories of programming languages:
 1. Machine languages. (low-level languages)
 2. Assembly languages.
 3. High-level languages.
4
Programming Languages (cont’d)
 A Machine language program consists of a sequence of zeros and ones.
 Each kind of CPU has its own machine language.
 Advantages
 Fast and efficient
 Machine oriented
 No translation required
 Disadvantages
 Not portable
 Not programmer friendly
5
Assembly Language
 Assembly language programs 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:

8086 Machine language program for
var1 = var1 + var2 ;
8086 Assembly program for
var1 = var1 + var2 ;
1010 0001 0000 0000 0000 0000
0000 0011 0000 0110 0000 0000 0000 0010
1010 0011 0000 0000 0000 0000
MOV AX , var1
ADD AX , var2
MOV var1 , AX

6
High-Level Programming Languages
 A high-level language (HLL) has two primary components
 (1) a set of built-in language primitives and grammatical rules
 (2) a translator
 A HLL language program consists of English-like statements that are
governed by a strict syntax.
 Advantages
 Portable or machine independent
 Programmer-friendly
 Disadvantages
 Not as efficient as low-level languages
 Need to be translated
 Examples : C, C++, Java, FORTRAN, Visual Basic, and Delphi.
7
Programming Paradigms
 Why are there hundreds of programming languages in use today?
 Some programming languages are specifically designed for use in certain applications.
 Different programming languages follow different approaches to solving programming problems
 A programming paradigm is an approach to solving programming problems.
 A programming paradigm may consist of many programming languages.
 Common programming paradigms:
 Imperative or Procedural Programming
 Object-Oriented Programming
 Event driven programming
8
8
Procedural
programming paradigm
9
Procedural programming
 Often thought as a synonym for imperative programming.
 Specifying the steps the program must take to reach the desired state.
 Based upon the concept of the procedure call.
 Procedures, also known as routines, subroutines, methods, or functions
that contain a series of computational steps to be carried out.
 Any given procedure might be called at any point during a program’s
execution, including by other procedures or itself.
 A procedural programming language provides a programmer a means
to define precisely each step in the performance of a task. The
programmer knows what is to be accomplished and provides through
the language step-by-step instructions on how the task is to be done.
 Lisp, C++, and Python are multi-paradigm; you can write programs or libraries that are largely
procedural, object-oriented, or functional in all of these languages.
10
10
Procedural programming
 Benefits:
» Often a better choice than simple sequential or unstructured programming in many
situations which involve moderate complexity or require significant ease of
maintainability.
» The ability to re-use the same code at different places in the program without copying it.
» An easier way to keep track of program flow than a collection of “GOTO” or “JUMP”
statements (which can turn a large, complicated program into spaghetti code).
» The ability to be strongly modular or structured.
 The main benefit of procedural programming over first- and second-generation languages is
that it allows for modularity, which is generally desirable, especially in large, complicated
programs.
 Modularity was one of the earliest abstraction features identified as desirable for a
programming language like Python
11
11
Procedural programming
 Disadvantages
difficulty of reasoning about programs
difficulty of parallelization.
Tend to be relatively low level.
Sample code:
12
Object-oriented
programming paradigm
13
13
Object-oriented programming (OOP) is a programming paradigm that uses
“objects” – data structures encapsulating data fields and procedures together
with their interactions – to design applications and computer programs.
Associated programming techniques may include features such as data
abstraction, encapsulation, modularity, polymorphism, and inheritance.
Though it was invented with the creation of the Simula language in 1965, and
further developed in Smalltalk in the 1970s, it was not commonly used in
mainstream software application development until the early 1990s.
Many modern programming languages now support OOP.
Object-oriented programming
14
14
A class defines the abstract characteristics of a thing (object), including that
thing’s characteristics (its attributes, fields or properties) and the thing’s
behaviors (the operations it can do, or methods, operations or
functionalities).
One might say that a class is a blueprint or factory that describes the nature of
something.
Classes provide modularity and structure in an object-oriented computer
program.
Collectively, the properties and methods defined by a class are called its
members.
OOP concepts: class
15
15
» An object is an individual of a class created at run-time trough object
instantiation from a class.
» The set of values of the attributes of a particular object forms its state. The
object consists of the state and the behavior that’s defined in the object’s
class.
» The object is instantiated by implicitly calling its constructor, which is one
of its member functions responsible for the creation of instances of that
class.
OOP concepts: object
16
16
An attribute, also called data member or member variable, is the data
encapsulated within a class or object.
Attributes are an object’s variables that, upon being given values at
instantiation (using a constructor) and further execution, will represent the
state of the object.
A method is a subroutine that is exclusively associated either with a class (in
which case it is called a class method or a static method) or with an object (in
which case it is an instance method).
Like a subroutine in procedural programming languages, a method usually
consists of a sequence of programming statements to perform an action, a set
of input parameters to customize those actions, and possibly an output value
(called the return value).
OOP concepts: attributes & Methods
17
17
 Inheritance
 Abstraction
 encapsulation and information hiding
 polymorphism
OOP concepts:
18
Programming Paradigms: Object-Oriented
Example object oriented languages include: Java, C#, Smalltalk, Python, c++ etc
 Advantages
 Conceptual simplicity
 Models computation better
 Increased productivity.
Disadvantages
Can have a steep learning curve, initially
Doing I/O can be cumbersome
19
19
Procedural programming vs OOPS
 The focus of procedural programming is to break down a
programming task into a collection of variables, data
structures, and subroutines, whereas in object-oriented
programming it is to break down a programming task into objects
with each “object” encapsulating its own data and methods
(subroutines).
 The most important distinction is whereas procedural
programming uses procedures to operate on data structures,
object-oriented programming bundles the two together so an
“object” operates on its “own” data structure.
20
Event-driven
programming paradigm
21
Event
 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. An event-driven application is designed to detect events as they occur,
and then deal with them using an appropriate event-handling procedure. The idea is
an extension of interrupt-driven programming of the kind found in early command
line environments such as DOS, and in embedded systems (where the application is
implemented as firmware).
 Event-driven programs can be written in any programming language, although
some languages(Visual Basic for example) are specifically designed to facilitate
event-driven programming, and provide an integrated development environment
(IDE) that partially automates the production of code, and provides a
comprehensive selection of built-in objects and controls, each of which can respond
to a range of events. Virtually all object-oriented and visual languages support
event-driven programming. Visual Basic, Visual C++ and Java are examples of
such languages.
22
Event Driven Programming
 User-Centric
 Computer User Determines the Order of Actions
 Programs are Interactive
 Flow of Control is Determined at Runtime
» User Clicks Mouse / Presses Key
» Object in Scene Moves to create a Condition
23
Event Handling
 Advantages
– It allows for more interactive programs. Almost all modern GUI programs
use event driven programming.
– It can be implemented using hardware interrupts, which will reduce the
power used by the computer.
– It allows sensors and other hardware to easily interact with software.
Disadvantages
– For simple programs, event driven programming is often more complex
and cumbersome than batch programming.
– The flow of the program is usually less logical and obvious.
24
Which Programming Paradigm is Best?
Which of these paradigms is the best?
 The most accurate answer is that there is no best paradigm.
 No single paradigm will fit all problems well.
 Human beings use a combination of the models represented by these paradigms.
 Languages with features from different paradigms are often too complex.
 So, the search of the ultimate programming language continues!
25
25
References
1. John von Neumann. First Draft Report on the EDVAC, 1945.
2. Harold Abelson, Gerald Jay Sussman. Structure and Interpretation of Computer Programs. The MIT
Press. 1996.
3. Roberts, Eric S. (2008). “Art and Science of Java; Chapter 7: Objects and Memory”. Stanford
University.
4. Programming paradigms, https://blog.newrelic.com/2015/04/01/python-programming-styles/

AssignmentTutorOnline

For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102