Object Oriented Programming vs Functional Programming vs Procedural Programming

Ishan Tiwari
2 min readMay 11, 2021
Photo by Florian Olivo on Unsplash

In this post we shall discuss the two widely used programming terms which are OOP (short for object oriented programming) and functional Programming.

Procedurals

Earlier when people did not have these two people used to write code line by line and for doing the same kind of task they had to write that code all over again. This was because the earlier programming langauges did not support functional and object oriented programming these programming langauages were the oldest and were known as procedural programing langauges.

These Programming lanuguages executed things line by line by the interpreter in this case the code can’t be reused.

#Pyhon Procedural
a = 5
b = 5
sum = a + b

Functional Programming languages

These languages had to be distributed into functions and each function had some procedural code.

It completely revolutionised things as code could be reused. Global functions also took place which can be called anywhere anytime inside language.

The functions can be called anytime and may be given different arguments too.

#Functional Programming in Python#main function, it executes when the script starts
def main():
a = 5
b = 8
sum = a + b
print(sum)
#if module hasn't been imported and startedif __name__ == '__main__':# Run main
main()

Object Oriented programming

In these languages programmers could create their own data types and give them their own methods. An object had several propeties and methods and you could use them anytime this was used in websites, modern apps and programming langauges like Python, Java, C++, etc.

#Python Object Oriented Code#app class
class App:
# Constructor defining properties#self = instance of the class
def __init__(self):
self.name = 'Example app'
self.description = 'Something Special'
#Method of the instance
def run(self):
print(self.name + " " + self.description)
if __name__ = '__main__':#creating instance of the class
x = App()
#Running the method of the instance
x.run()

The objects can have several instances and the instances may have same or different properties.

Comment if you’d like to have my python object oriented course

--

--

Ishan Tiwari

A Linux enthusiast working on small scale django and react projects