OOP vs Functional Programming

You’ve likely known about Object Oriented Programming, as it’s the most famous type of programming today, yet numerous individuals appear to need information on the lesser known method, Functional programming. For this it will be going over how it varies from object oriented programming, and what are the advantages of the two methods.

Object Oriented Programming

To comprehend the contrasts between functional programming and object oriented programming, first you need to comprehend what precisely is object oriented programming. In object oriented programming you are gathering gatherings of related variables and capacities, into a particular unit, also called an “object”(this can be considered as a gigantic advantage, as you have an unmistakable method of organizing everything, and can help when managing complex frameworks). These objects can have properties, and strategies. You can consider a property a variable, and each of the variables focuses on a worth. For instance, in the event that you needed to make ” var car = ‘ABC’ “as a property with a worth, rather you would compose this as var car = {model: ‘ABC’}. Straightforward right? Presently a technique is basically a capacity that may be identified with that object. For instance, a car can likewise have a technique for ‘start’. on the off chance that you needed to compose this in an object.

One of the enormous advantages to OOP is that you can limit repetitive/rehashing code by inheritance. for instance, on the off chance that you had a lot of vehicles, you wouldn’t need to compose techniques for each and every one of them, as the strategies for start(), stop() can be acquired by all vehicles. This identifies with the last point for OOP, which would be polymorphism. In OOP you can have a beginning() technique for vehicles, however the strategy may act diversely relying upon the vehicle you are referring to ( A vehicle may be electric, beginning the battery, over a customary vehicle, which will turn on its motor).

Functional programming

Functional programming varies in a couple of various ways. In functional programming, you should have what’s designated “pure functions” which implies that a capacity should have no side effects(the work itself should have nothing that doesn’t assist with yielding its return esteem), and should not highlight any global variables, as the capacity ought to have the option to chip away at its own. Some may say this is an advantage of functional programming as you don’t need to consider or allude to whatever is outside the capacity. Something else present in functional programming would be what’s classified “immutable data”, which in straightforward words implies, try not to have the option to change any of the variables made (you can reenact this impact in JavaScript with the freeze method). On the off chance that you need to, you make another variable, however never change the current one. One more typical thing you will see in Functional programming is functions that yield different functions. A basic model might be, if you somehow happened to deduct two distinct numbers you may have a capacity that creates another capacity that will take away numbers. This can rapidly get exceptionally mind boggling, however this article here goes into it in more detail. 

In spite of the fact that OOP is “lord” right now, Functional Programming is filling in prominence, and more highlights are being carried out in dialects that permit an ever increasing number of individuals to work with this training (like the freeze method). This article doesn’t go into outrageous detail of both programming methods, however I trust this has at any rate motivated you to test, and accomplish more examination for the two ways to deal with see which you may like the best.