HACKER Q&A
📣 yoda_yoda

OOP vs FP?


Why is OOP bad than FP? What are the specific advantages with FP? Can OOP be implemented by FP and vice versa?


  👤 codemonkey-zeta Accepted Answer ✓
I think there's a false dichotomy which pervades discussion of programming "paradigms". They're all tools with specific jobs, and a good programmer will be a master of many.

OOP is a tool designed for a certain class of problems - problems which are adequately modeled by message-passing entities. A desktop environment is the perfect example.

FP is a tool well-suited to other problems. If I wanted a system to manage facts about some domain, and change those facts based on outside stimuli, I would be inclined towards a purely functional system operating on immutable data structures. Think about the proliferation of redux in web development and you'll see this is exactly the model of user interaction with a single-page web application.

If I wanted a system that closely interacted with a number of chips/hardware components with extremely fine-grained control, I would use an imperative approach.

All these paradigms have their purpose. It's when programmers get dogmatic about a certain paradigm where insane levels of complexity arise. Know your tools, and use them appropriately.


👤 croo
OOP is for structuring application code, FP is for structuring flow and make reasoning easy. They are different paradigms but can be used hand in hand. To be stateless and single responsibility is as desirable in Java as well as in Haskell, the way you achieve it depends on the tooling.

👤 ksaj
Take a look at Common Lisp. That's about as close as I think one can get to a seamless melding of FP with OOP (using Common Lisp Object System, CLOS). Mind you, it doesn't look very much like OOP in Java, but it covers the same territory.

👤 yoda_yoda
Thanks a lot for all of your insightful comments. This is really interesting.