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

Lesson 2 - Programming Paradigms

Uploaded by

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

Lesson 2 - Programming Paradigms

Uploaded by

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

DIT 305: PROGRAMMING METHODOLOGY

Lesson 2: Programming paradigms

1.12. Introduction
In our last lesson we introduced programming concepts like program, programmer, bug, syntax
among others as well as program development life cycle. In our lesson today we will be discussing
programming paradigms. Paradigm refers to a way of organizing thoughts. Programming paradigm in
particular refers to basic structuring of thoughts underlying the programming activity. There are four
basic programming paradigms: Imperative, functional, object oriented and logic paradigms.

1.13. Lesson objectives


By the end of this lesson the learner will be able to:
 State and describe major programming paradigms.
 Discuss the structured programming paradigm.

1.14. Lesson outline
This lesson is structured as follows:
2.1. Introduction
2.2. Lesson objectives
2.3. Lesson outline
2.4. Imperative paradigm
2.5. Functional paradigm
2.6. Object oriented paradigm
2.7. Logical paradigm
2.8. Structured programming
2.8. Revision questions
2.9. Summary
2.10. Suggested reading

1.15. Imperative paradigm


Programming involves ordered steps for solving a problem (procedural programming).
Computations are performed through a guided sequence of steps, in which these variables are
referred to or changed. The order of the steps is crucial, because a given step will have
different consequences depending on the current values of variables when the step is
executed. [i]. Based on digital hardware technology and the ideas of Von Neumann [ii].
Involves incremental change of the program state as a function of time.
[iii].Execution of computational steps(commands) in an order governed by control
structures
[iv]. Similar to descriptions of everyday routines, such as food recipes and car repair
[v]. The natural abstraction is the procedure
Advantages
[i]. There are minimal programming steps for solving a problem.
[ii]. Proving the validity of a given program is simple.
DIT 305: PROGRAMMING METHODOLOGY

[iii].Have low memory utilization


[iv]. They relatively efficient
[v]. The most common form of programming in use today.
Disadvantages
[i]. Difficulty of reasoning about programs
[ii]. Difficulty of parallelization.
[iii].It tends to be relatively low level.

1.16. Functional paradigm


Programming involves evaluating functions and using the results. The functional programming
paradigm views all subprograms as functions in the mathematical sense-informally, they take in
arguments and return a single solution. The solution returned is based entirely on the input, and the
time at which a function is called has no relevance. The computational model is therefore one of
function application and reduction.
[i]. It is based on mathematics and theory of functions
[ii]. Time only plays a minor role compared to the imperative paradigm
[iii].All computations are done by applying (calling) functions
[iv]. Abstracts a single expression to a function which can be evaluated as an expression
[v]. Functions are full-fledged data just like numbers, lists,

Advantages
[i]. The high level of abstraction which results into fewer errors.
[ii]. Not dependent on assignment operations, allowing programs to be evaluated in many
different orders.
[iii].More amenable to mathematical proof and analysis.

Disadvantages
[i]. Less efficient
[ii]. Not useful for problems involving many variables or a lot of sequential activity.
1.17. Object oriented paradigms
Programming involves use of objects and how the communicate using messages.
[i]. Based on the theory of concepts, and models of human interaction with real world
phenomena.
[ii]. Data as well as operations are encapsulated in objects
[iii]. Information hiding is used to protect internal properties of an object
[iv]. Objects interact by means of message passing
[v]. In most object-oriented languages objects are grouped in classes.
[vi]. Provides for class extension or specialization

Advantages
[i]. Allows inheritance and hence code reuse
DIT 305: PROGRAMMING METHODOLOGY

[ii].Provides higher degree of modularity


[iii].Allows information hiding
Disadvantages [i]. The programs are generally
larger.
[ii].The speed of execution is relatively lower because of increased modularity and size.

1.18. Logical paradigms

Programming involves answering questions through search for solutions. The logic paradigm fits
extremely well when applied in problem domains that deal with the extraction of knowledge from basic
facts and relations.
[i]. Based on automatic proofs within artificial intelligence
[ii]. Based on axioms, inference rules, and queries.
[iii].Program execution becomes a systematic search in a set of facts, making use of a set of
inference rules Advantages
[i]. Good support for reasoning about programs [ii].
Can lead to concise solutions to problems
Disadvantages
[i]. Difficult to see what is actually happening computationally
[ii]. Slow execution
[iii].Difficulties in understanding and debugging large programs.

1.19. Structured programming


This is a sub discipline of procedural programming under imperative programming paradigm.
It works under the concept that programs use three structures namely: decisions, sequences and
loops. Using this paradigm, programs can be broken into smaller modules (sub routines). Hence it is
said to follow modular programming. There is no use of GO TO statement. It follows the principle of
divide and conquer.

Advantages of structured programming


[i]. Complexity can be reduced using concepts of divide and conquer.
[ii]. Logical structures ensure clear flow of control
[iii].Increases productivity by allowing multiple programmers to work on different parts of
the project independently at the same time.
[iv]. The modules can be re-used many times thus saving time.
[v]. It is easier to update/ fix the program by replacing individual modules rather than
larger amounts of code.

Disadvantages of structured programming


[i]. Since GO TO statement is not used, the structure of the program must be planned
carefully.
[ii]. The program lacks encapsulation
DIT 305: PROGRAMMING METHODOLOGY

[iii].There is same code repetition


[iv]. It lacks information hiding(abstraction)
[v]. Change of a data structure will require changes at many places throughout it and so
changes become difficult to track.
[a]. Top-down approach
Top-down approach involves breaking the overall procedure or task into component parts (modules) and
then subdivide each component module until the lowest level has been reached. It is also called top-
down design or top-down decomposition. The approach begins with the formulation of the overview of
the system but no details are given. Then the first level sub systems are specified but again no details are
given. Each of the sub systems is then refined to lower level subsystems. This proceeds until the entire
system is reduced to base elements. This approach is useful for brand new systems. This methodology
consists of hierarchy structure where details are added at each level.
[b]. Bottom-up approach
In this design approach the individual base elements (modules) of the system are first specified in great
detail. Involves writing the basic procedures (sub routines) that will be necessary at some point in the
programming and then work up to the more complex parts of the program. This methodology therefore
begins with description of the lowest level system components and how the components are assembled
to form higher level system components. This approach is sometimes used when reverse engineering a
design; i.e. when we are trying to figure out what somebody else designed in an existing system.

1.20. Non-structured programming


Mostly all the program code is written in a single continuous main program. The logic of the program is
difficult to follow with the program. Code from other programs is difficult to incorporate. It’s difficult to
test specific portions of the program. The program is also difficult to debug. Uses GO TO statement to
transfer from one part of the program to another. The connections between parts of the program using
GO TO can become quite haphazard. Such a code is referred to as spaghetti code.

1.21. Revision questions


[a]. Discuss the strengths and weaknesses of the following programming paradigms:
[i]. Imperative
[ii]. Functional
[iii].Logic
[iv]. Object oriented
[b].Differentiate between structured and non-structured programming [c].
Discuss the following approaches used in structured programming.
[i]. Bottom up approach
[ii]. Top down approach

1.22. Summary
In this lesson we have discussed the four programming paradigms. We have learnt that Paradigm
refers to a way of organizing thoughts. Programming paradigm in particular refers to basic structuring of
thoughts underlying the programming activity. There are four basic programming paradigms:
Imperative, functional, object oriented and logic paradigms.
1.23. Suggested reading
DIT 305: PROGRAMMING METHODOLOGY

[1]. An introduction to programming by Wu Thomas, Norman and Theodore: McGrill (1997). [2]. C
programming language by Brian W. Kernighan, Dennis Ritchie, 2nd ed: prentice hall(2003).
[3]. http://people.cs.aau.dk/~normark/prog3-03/html/notes/paradigms_themes-paradigm-overview-
section.html
[4]. http://larch.cs.iastate.edu/ComS541Fall97/hw-pages/paradigms/major.html
[5].C how to program by H.M. Deitel and P.J.Deitel, 3 rd ed: Prentice hall(2001).

You might also like