Functional vs Object-Oriented Programming. Pros and Cons.

Functional Programming

FP is a programming technique that is well known for its programs to be constructed by deploying functions. The main concept of FP is that it attempts to avoid changing state and mutable data. In a functional program, the output of a function should always be the same, given the same exact inputs to the function. Why is it so? Well, it is because the output of a function relies on its arguments. Let’s make it clear if you call a function subtract() it will return the difference between the values and in case you give the same input a and b, you will always get the same result.

Object-Oriented Programming

Object-oriented programming technique is essentially based on the concept of object which contains data in the form of attributes and code in the form of procedures (methods). The attributes in the objects are manipulated through methods that are given to that particular object. Example:

Example code.

Differences

Comparison between FP and OOP.

Pros and Cons

Everything in this world has both advantages and disadvantages, so it is worth knowing them before actually using something. Once we defined both FP and OOP we can discuss them.

FP Pros and Cons

+ Using clean and transparent functions leads to reliable results without side effects that deliver and return exactly what you expect.

OOP Pros and Cons

+ Objects and methods are very clear and understandable.

References:

https://sdacademy.dev/difference-between-functional-programming-and-object-oriented-programming/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store