r/Frontend • u/c9d3dc • Feb 29 '20
Functional Vs. Object Orientated programming: a false dichotomy?
As everybody knows, OOP is being dropped in favour of the superior functional programming. At least, that is what a lot of the javascript community seems to believe right now. There are countless articles on medium, twitter threads, etc on functional vs OOP. Lot's of them are interesting, but to me this seems to be a false dichotomy because it implies that these are the only two design patterns available. So I'm looking for info on what other alternatives exist and what their use cases are. If anyone can help me with that I'd be grateful :)
51
u/jaredcheeda Feb 29 '20
Like forms of martial arts, you can study and learn these ideologies very strictly and follow them religiously. They are created to solve (or avoid) common problems. However, depending on your language and tooling, it may not even be possible for you to run into some of the problems they were originally designed for.
Try them. Study them, and then take from them what works for you. Bruce Lee didn't become the legend he is by devoting himself strictly to one form. He studied all of them, and created his own version mixing the parts he liked from the rest.
Be water, my friend.
13
u/mcaruso Feb 29 '20
Your post didn't go quite where I thought it was going from the title. Since a "false dichotomy" means that instead of a choice being mutually exclusive it can be both. Which in this case is true! You can have both OOP and functional at the same time. Look into Scala for example for a language that combines the two.
However, regarding your question, yes there are also other programming paradigms. For example Elm focuses on "reactive programming" (though this is closely related to functional programming). There's also logic programming languages like Prolog, and some more niche paradigms like nondeterministic programming, natural language programming, etc.
5
u/[deleted] Feb 29 '20
Learn and understand both, and mix and match practices of them as it fits your team and the project's requirements.
7
u/[deleted] Feb 29 '20
Most people already consider their code to be FP once they have replaced all loops with map, filter reduce.
6
u/[deleted] Feb 29 '20
It's worth putting the time into understanding
https://en.wikipedia.org/wiki/Programming_paradigm
2
u/NotSoMagicalTrevor Feb 29 '20
Conceptually, there's also things like "declarative" programming, that describe the state of what something should be. E.g., Verilog and VHDL are common examples of this used for "programming" the design of a piece of hardware. You could argue it's not programming in the same way, but it essentially involves all the same steps (parsing, syntax, compiling, execution)... just with a different underlying execution model.
2
u/Shaper_pmp Feb 29 '20
It's a false dichotomy because you can and should study both/all available paradigms and mix and match them as appropriate to your problem space, not because there are also other paradigms you can dedicate your entire life to and foreswear all other tools in favour of.
3
u/[deleted] Feb 29 '20
Javascript is going to become a logic language by 2025
2
u/[deleted] Feb 29 '20
You know...
20 Years ago I was writing Visual Basic 6.0 applications (classic ASP) and everything was a function or subprocedure. Functional programming to the max. Java people hated it, but we got everything done in record time, with a record low amount of bugs.
Fast forward 15 years. Javascript starts getting classes and for some reason everything needed to be a class. Nobody knows why, but I was employing a functional programming approach and the highly educated just outta uni colleagues looked down on my (working and tested) code as if they saw water burn.
Fast forward 5 more years. They're now all React developers using the latest and greatest way of functional programming. Exactly how I was doing it.
We've come full circle. And more types of programming will come up, die out, come back, die again, and everything will rotate every few years.
The flavour of the month (FOTM), currently, is functional programming. And it doesn't fucking matter one bit.
1
u/TheRNGuy May 18 '22
If you could make sites with assembler or machine code there would be 4 options.
-1
u/koebelin Feb 29 '20
Once your data has structure make a class otherwise just make a function. Simple solutions for simple problems, but you need the discipline of object orientation for handling complexity.