DEV Community

Cover image for The two universes of programming! OOP and FP!

The two universes of programming! OOP and FP!

Adnan Babakan (he/him) on July 01, 2020

Hey there DEV.to community! A lot of people getting into programming hear two words really often! OOP and FP! Which OOP has the advantage in their...
Collapse
 
_hs_ profile image
HS

More like class oriented vs FP. Take a look what Alan Kay wrote about OO after classes happened. He regrets calling it that way now and more focuses on some FP as actual OO with of course some side effects. Also creator of Erlang (known as FP) in 2006 (find youtube video) called it real OO and referenced Kay's statement.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Hi
I will check these things you've mentioned out for sure, thanks. But all in all, I think this is how OOP and FP are considered right now.

Collapse
 
_hs_ profile image
HS

Sure, I think it doesn't matter what creator meant but how people ended up using it. Just fun thing about computers, it's usually different than expected. Like did Unix people intended for C to be this big? No, they intended Unix to be the main thing but they both got in history. The Sims game was started as tool for architects and look where it ended. Fun I guess

Thread Thread
 
adnanbabakan profile image
Adnan Babakan (he/him)

Well, I did know about all the computer stuff you mentioned more or less. But about Sims? No way. How come? LOL xD :))))

Thread Thread
 
_hs_ profile image
HS

Yup, Will Write was working on a tool for 3D modeling because of architects or such, you can research more but I remember something about it written when first Sims was out

Collapse
 
erikpischel profile image
Erik Pischel

I I think that you explained some concepts incorrectly. encapsulation for example, wikipedia defines "encapsulation refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an object's components."

polymorphism isn't about performing multiple tasks. it's about variables referencing objects that do not have the declared type but another (often derived) type.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Hi
Thanks for your comment
I think we are both on the same page

Collapse
 
610yesnolovely profile image
Harvey Thompson • Edited

Great summary of the two different paradigms.

Personally I'd recommend starting with OOP (or even imperative/declarative), because we often think about "Nouns" (class) and "Verbs" (method), and our minds are good at breaking down problems into categories and hierarchies.

However, one should also learn functional program - even in a non-functional language. The reason is that computer power is still increasing exponentially, but now that power comes from having multiple CPUs and threads.

Working with immutable data (see also persistent data structures) in functional languages with multiple threads/CPU is much easier to reason about, compared to working with mutable data, threads/locks (though knowing about such things is very important).

Modern programming languages are typically multi-paradigm, and we're seeing more and more functional ideas being applied in historically OOP languages.

So, learn both :-D

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Hi
Thanks for your comment
Yes OOP is good to start with but learning FP opens a new universe in a programmer's mind due to immutables and so.

And yes I love how OOP langauges are adopting FP features.

Collapse
 
scilari profile image
Ilari Vallivaara • Edited

Where do you get that FP could not use objects? For example, even Haskell has objects; an (immutable) class is one (good) way to define a data structure or a mathematical object, such as a complex number. These are perfectly usable by pure functions and FP in general.

I think this post kind of misses the point of these two paradigms by treating them as opposite and non-overlapping sides of programming. This is mainly due to not recognizing the key aspects of OOP and FP. Why isn't FP compared to imperative programming and OOP to something that does not bundle the functionality and data, instead?

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him) • Edited

Hi
Thanks for your comment
I know that OOP and FP can have many things in common. I just wanted to give a general idea about these two and the general thing about FP is that they don't use classes and objects. I will try to write an article more detailed about imperative and declarative programming later.

Collapse
 
sjf3 profile image
Sam Fleeman

You should look at golang. It's a different kind of OOP. No classes. You get class like behavior from having struct or struct pointer function receivers. No inheritance either. You have struct embedding and implicit interface fulfilment to accomplish similar things. Go also has first class functions so while not being optimized for tail recursion you can do some functional things. Look up Dave Cheney's functional options blog post/talk for an example of first class functions providing OOP like data encapsulation. My point is java style OOP is not the only way to OOP and not forcing you into making everything an object is actually less verbose. Sometimes you just need a utility function it's not an object it's not even related to an object. GetTerraformPluginDir( ) for example. It's different on windows or mac/Linux. The function has to determine the OS and build a string I don't need a class for this and I might want to reuse this logic across multiple "classes"

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

Hi
Thanks for your comment
Yes, I know there are other approaches to OOP. And I've also written an article about Go which you can check it out here: