OOP vs FP

Ramazan Ramazanov
2 min readFeb 22, 2021

Object Oriented Programming and Functional Programming. They are both paradigms and a programming paradigm is writing code compliant with a specific set of rules. For example, organizing the code into units would be called Object Oriented Programming. Avoiding side effects and writing pure functions would be called Functional Programming.

In Object Oriented Programming and object is a box containing information and operations that are supposed to refer to the same concept or grouping it as an object. These pieces of information inside of the objects are called attributes or state and the operations that can happen on the state are known as methods.

In Functional Programming the code is essentially a combination of functions and data is immutable which leads to writing programs with no side effects and pure functions. This is because in a Functional Programming paradigm that function cannot change the outside world and the output value of a function simply depends on the given arguments. This allows Functional Programming to really have control over a program flow.

It is known that Functional Programming is based on different concepts. We have higher order functions, pure functions, referential transparency. In Functional Programming functions are first class citizens, while in Object Oriented Programming objects are first class citizens. In Object Oriented Programming we have abstraction, encapsulation where it allows us to encapsulate ideas that are related together and objects. It helps us hide irrelevant data from the user.

Object Oriented Programming has been around for a long time since the 70s, Functional Programming as well, if not even earlier. Object Oriented Programming is very common in languages like C++, Python, Java, when Functional Programming is very common in languages like Closure and Haskell. But at the end of the day none of these is better than the other. All of them are good in their own ways. They are simply different approaches to the same problem. To be clear the advantage of each paradigm is simply in the modeling of your algorithm and data structures. The choice of which you use is simply what makes more sense for your project and the language that you use.

--

--