DEV Community

Discussion on: Is Object-Oriented Programming "Dangerous"?

Collapse
 
akashkava profile image
Akash Kava • Edited

I have explained it here, I found his claims very funny, cheap is a really wrong word, functional programming is like a building Rocket for transportation from home to office, which ofcourse is expensive and requires great minds, but do we really need it? I would use a simple car without understanding E=mc*2, it doesn't mean car or I am cheap.

This is exact same comment on different article by me, dev.to/akashkava/comment/7fig

Coding consists of two major parts, one logic and one is organizing logic. Consider logic as a contents of book and organizing as a book library.Book Library is organized by categories and then it is further organized by either author name or title in dictionary form. Imagine if you had a good contents of book but if it wasn't organized properly. Imagine if everyone organize contents of book and book in library with random order.

I consider class as a way to organize logic, you still have your functional ways to write logic but class is well understood by everyone and it is easy to document and organize. And it is very easy to refactor the code because IDE knows all references of identifier and it can safely refactor it. This was basically the reason why C++, Java and C# became more popular because developers need not focus on how to write it correctly and were able to focus on business needs.

Ideally doing everything in OOP or everything in Functions, both are bad, you must choose OOP to organize your logic, which is extremely important for long term healthy library and functions to improve your logic.

Functional programming represents Science computations closely so it is easy to use it for Rocket Science, OOPS is more for business applications.

More than anything important, I see that they outline frustration of not being able to do one thing easily in OOPS that they were able to do it easily in other paradigm, that doesn't make OOPS a trillion dollar mistake !!

Collapse
 
furkanthehuman profile image
Furkan Aksoy

Functional programming is not that abstract. Just the paradigm is different. So it feels unintuitive because most people are not familiar with patterns.

Collapse
 
oenonono profile image
Junk

That's what intuitive means, man. It means it's similar to something you already understand. So for human beings, there are three broad categories of intuitive. Biological/environmental, sociocultural, and trade/domain. Some things are intuitive because they exist in nature. Some things are intuitive because they are taught in childhood. Some things are intuitive after having experiences in a specific domain.

OOP is intuitive based on all three, arguably, but definitely based on the latter two. Most languages people use have subjects, objects, verbs, and adjectives. We learn those languages as children and use them with all our co-workers, not just other programmers.

Advanced math, however, is only intuitive based on the third.

Thread Thread
 
furkanthehuman profile image
Furkan Aksoy

Okay, you are right about intuition but still, functional programming does not mean advanced math. At least not always.

OOP has strong logical and academic bases. But in day to day life, we don't use words like polymorphism or encapsulation.

Most of the functional code is things like, being side effect free or use of high order functions. So things like category theory and stuff is mostly proof of concept.
The pareto principle

Thread Thread
 
combinatorylogic profile image
combinatorylogic • Edited

Please stop pretending that natural languages have anything to do with this useless and fully artificial notion of "objects" that any of the OOP definitions is dealing with.

steve-yegge.blogspot.com/2006/03/e...

Thread Thread
 
furkanthehuman profile image
Furkan Aksoy

What? I did not say anything about natural languages

Thread Thread
 
combinatorylogic profile image
combinatorylogic

Yep, sorry, I misread your answer in a context of this thread.

 
sixtynine profile image
Dan

In day to day life, polymorphism is when you get a can of pepsi instead of a bottle of coke, and the way we get our food in a restaurant is strongly encapsulated :)

Thread Thread
 
shovelmn12 profile image
shovelmn12

It doesn't matter... At the end of day to write oop takes more time more code and harder to refactor

For example

list.map(mapToWhatever)
.filter(onlyBlue)
.map(getChildren)
...etc

Easy to read and understandable, who ever thinks its not shouldn't be programming.
The same 4 lines in oop would be maybe 30 including 3 different interfaces and 4 different classes and to refactor such a thing is much more complicated than adding one line that describes exactly what you want.

Plus look closely lots of the leading frameworks are fp... Express react redux flutter swiftui Compose etc...

FP + Declarative = easy to read and understand

Thread Thread
 
oenonono profile image
Junk

Yep! That's why I think a mix of both is usually best—at least for the code I write.

 
sixtynine profile image
Dan

My point is that OOP is intuitive because it tries to model the reality.

I don't deny the virtues of FP, I use it.

As well as OOP.

Thread Thread
 
akashkava profile image
Akash Kava • Edited

list.map(mapToWhatever)
.filter(onlyBlue)
.map(getChildren)

Writing . before name of function is called Encapsulation, even in FP, you are using some OOPS, remove . and then write everything, and see how many problems will arise!!!

By the way you can do that in C#

list
   .Select( x => ((x.Property1, x.Property2)));
   .Where(x => x.Property1 > 20)
   .Select(x => x.Property2);

The biggest advantage here is, strong typing, and class relationships allows IDE to provide intellisense and provide compile time errors way before the code's execution. These are other benefits of OOPS, though such things are possible in FP as well but I don't think the level of advance IDE matches anywhere near to OOPS IDEs have already mastered.

There is no end of such argument, I said in the beginning and even I am repeating, you have to use best of both worlds !! Don't try to overdo by doing everything in FP just to show off, its not worth it.

Thread Thread
 
oenonono profile image
Junk

But as someone else has already pointed out, that example is OOP—and, in fact, may only be FP depending on how the functions passed into the methods are actually implemented.

list is the object (the subject)
map, filter, are methods of the object (the verbs)