0% found this document useful (0 votes)
2 views16 pages

Computer Programming Chapter 2

This chapter covers programming paradigms, which are different styles of organizing programs and languages. It explains various paradigms such as Imperative, Procedural, Functional, Declarative, and Object-Oriented Programming, highlighting their characteristics and suitable applications. Additionally, it discusses how programming languages can be aligned with specific paradigms or be multi-paradigm, allowing flexibility in coding approaches.

Uploaded by

paavohamatwi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Computer Programming Chapter 2

This chapter covers programming paradigms, which are different styles of organizing programs and languages. It explains various paradigms such as Imperative, Procedural, Functional, Declarative, and Object-Oriented Programming, highlighting their characteristics and suitable applications. Additionally, it discusses how programming languages can be aligned with specific paradigms or be multi-paradigm, allowing flexibility in coding approaches.

Uploaded by

paavohamatwi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Programming I

Chapter 2
Programming Paradigms
Learning Objectives
In this chapter, you will learn about

• Know what a paradigm is


• Know the different programming paradigms there is
• Differentiate between different programming languages and what paradigm best suits them

2
Programming Paradigms

• Programming paradigms are different ways/styles in which a given program or programming language can
be organized.
• Each paradigm consists of certain structures, features, and opinions about how common programming
problems should be tackled.
• Certain paradigms are better suited for certain types of problems.
• It makes sense to use different paradigms for different kinds of projects

3
Paradigms and Programming Languages

• A programming paradigm is not a language nor a tool.


• You can't build anything with it
• They are a set of ideals/guidelines that many people have agreed on, followed and expanded
• Programming languages aren't always tied to a specific paradigm

4
Paradigms and Programming Languages

• Some languages have been built with a certain paradigm in mind and have features that facilitate that kind
of programming more than others.
• Example: Haskel and Functional Programming
• There are also multi-paradigm languages.
• Meaning you can adapt your code to fit a certain paradigm or another
• Javascript and Python are good examples.

5
Commonly Used Programming Paradigms

The following are the commonly used programming paradigms:

• Imperative/Sequential Programming
• Procedural Programming
• Functional Programming
• Declarative Programming
• Object Oriented Programming

6
Imperative/Sequential Programming

• This kind of programming paradigm consists of sets of detailed instructions that are given to the computer
to execute in that order.
• It is called imperative because as a programmer, we dictate exactly what the computer has to do in a
specific way.
• It focuses more on how a program operates step-by-step

7
Imperative/Sequential Programming

Using an actual code example, let's say we want to filter an array of numbers to only keep the elements
greater than 5, our computer code can look like this.

We are telling the program to iterate through each element in the array and compare the item value with 5.
if the item is higher than 5, push it into another array

8
Procedural Programming

• This is the derivation of imperative programming,


adding to it the feature of functions
• Functions are also known as procedures or
modules or subroutines

9
Functional Programming

• Here, functions are treated as first class citizens


• Meaning they can be assigned to variables, passed on as arguments and returned from other functions
• A pure function is the one that rely only on its input to generate its result
• Functional programming improves code maintainability

10
Functional Programming

11
Declarative Programming

• It is all about hiding away complexity and bringing programming languages closer to human language
and thinking.
• It is the direct opposite of imperative programming in the sense that the programming does not give
instructions about how the computer should execute the task.
• But rather on what result is needed

• We are not explicitly telling the computer to iterate over the array or store the values in a separate array
• We just say what we want ("filter") and the condition that must be met ("num>5")

12
Object-Oriented Programming

• OOP is one of the most popular programming paradigms.


• The core concept of OOP is to separate concerns into entities which are coded as objects
• Each entity will group a given set of information (properties) and actions (methods) that can be
performed by the entity
• OOP makes usage of classes which are a way of creating new objects starting out from a
blueprint/boilerplate that are programmer set
• OOP also make usage of objects that are created from a class called an instance
• Following our pseudocode for the baking example, let's say we have a main cook and an assistant
cook.
• Each of them will have certain responsibilities in the baking process

13
Object-Oriented Programming

Using OOP, our program will look like this:

14
Object-Oriented Programming

15
Thank You

16

You might also like