Name: Joel James P. Alao Assignment 1
Name: Joel James P. Alao Assignment 1
Alao
Assignment 1
1. Imperative Programming
Refers to a development paradigm that utilizes functions that must be coded in e
very step in order to solve a problem. Every part of the operation as well as the e
ntire code itself explains in specific details on how the problem was solved. As su
ch, this type of paradigm requires an adequate amount of understanding of the fu
nctions necessary to solve various problems. To put it simply, this paradigm is es
sentially giving out a set of instructions to solve a problem at hand without any he
lp from any models.
An example of this programming Paradigm is C++, which was created and devel
oped by a Danish computer scientist named Bjarne Stroustrup, which he conseq
uently built upon the C programming language which was developed by Dennis
Ritche.
Sample code of Imperative programming paradigm with C++:
Figure 1.1
This figure shown above (see Figure 1.1) basically prints out the output of the sum of three num
bers as well as its average. As you may have observed, the code had to implicitly add functions
step-by-step in order to reach the desired outcome of the program.
2. Object-Oriented Programming
This paradigm refers to the usage of classes and objects as a way to re-use code
like a blueprint. This makes programming much more simpler and less of a hassl
e.This lets users have libraries/modules which they can either create or import th
at can help with creating their desired programs.
A class refers to an abstract blueprint that focuses on creating objects which has
sets of attributes. Essentially, class defines the attribute of an object, but not its v
alue. (Eg. A class specified for cars have an inherent attribute of having a body ty
pe of all the objects but its value such as the shapes of the parts or its color could
not be specified by its class.)
An object refers to an instance that resides within a class. This have sets of attrib
utes that are declared in the class.
To summarize, OOP (Object-Oriented Programming) basically use the concepts
of class and objects to make codes re-usable and much simpler to utilize.
An example of OOP is Java, which was developed by a Canadian computer scie
ntist named James Gosling, where he and along with his team of researchers cre
ated a programming language that allows electronic devices to communicate with
one another
Sample of Object-Oriented Programming paradigm with Java:
Figure 1.2
The figure shown above (see Figure 1.2) created a class named Dog as a blueprint for the objec
ts with attributes like breed, size, age, and color. This program creates an object within the class
with assigned values in the breed, size, age, and its color. As observed, it utilizes the concept of
classes and objects to create a simple and easily digestible code.
3. Functional Programming
This type of paradigm utilizes functions to its fullest in order to create a clean and
maintainable software, this basically uses immutable variables and pure function
s which has no side-effects other than the results that come out of it. Because of i
ts flexibility, functional programming was even utilized in many high-level progra
mming languages such as Python and Java.
This type of paradigm also has its called a Referential Transparency which states
that functional programs should always be like how it was the first time it ran, if th
ere were any problems in the program, you would know immediately that somethi
ng must have happened during the program’s execution, and its side-effects alon
g with it and you’d never have to put a blame on its functions.
Functional Programming focuses entirely on evaluating the results that come out
of the function, which is mostly used to collect data or machine learning due to its
characteristic of having no side-effects other than the results as opposed to other
types of programming such as Imperative programming and Object-Oriented pro
gramming which can have a side-effect of modifying the state of the program or t
aking input of a user.
To put this paradigm in the most simplistic of words, its approach treats functions
as a first-class citizen, and because of how it couldn’t have any side-effects due t
o its data being immutable, it is mostly used in machine-learning and data collecti
on.
To demonstrate what functional programming is, a sample code has been made
to replicate the multiplication of the original array without changing anything aside
from the result shown below. The programming language used is Python which
was created by a Dutch programmer named Guido van Rossum which he
became one of the world’s most influential programmers because of his works.
An example of Functional Programming in Python:
Figure 1.3
As shown above (Figure 1.3) this code is called a pure function because its function does not ha
ve any references to any variables outside of it. Since there isn’t anything that can change the v
alue of a variable, we are definitely guaranteed to have the same result over and over again. He
nce, this is considered functional programming as the data could not be altered.
4. Logic Programming
A type of computer programming paradigm in which the program has a set of rule
s and logic that is expressed about a problem using a system of formal logic. Thi
s language has sentences that follow logic so as they can express facts and rule
s.
For computer programs to make use of logic programming, it uses logical inferen
ces according to the available data at a given moment. This paradigm also use a
base of existing logic called a predicate, this can also be used to create atoms, w
hich basically means a sentence that could not be broken down into a much mor
e simpler sentence. Predicates and atoms are primarily used to form queries in w
hich this paradigm uses to display relevant data.
A very well known logical programming knowledge known as Prolog evolved out
of the research of a French computer scientist named Alain Colmerauer, he creat
ed the Prolog language which was further improved by a logician named Robert
Kowalski to what it is today.
An example of Logic Programming in Prolog:
Figure 1.4
The codes above shows a snippet of a code made in Prolog, this code basically finds out if Sally
and Erica are siblings. The code uses logical inferences according to the data shown above to s
ee if the inquiry is a Yes or a No.
References:
1. (2018, November 27). imperative programming. WhatIs.Com.
https://www.techtarget.com/whatis/definition/imperative-programming#:
%7E:text=Imperative%20programming%20is%20a%20software,models%20are
%20not%20called%20on.
6. Hartman, J. (2022, June 25). What is Class and Object in Java OOPS? Learn
with Example. https://www.guru99.com/java-oops-class-objects.html
11. Atom in first order programming. (2019, February 3). Mathematics Stack
Exchange. https://math.stackexchange.com/questions/3098223/atom-in-first-
order-programming