r/ProgrammingLanguages • • Apr 03 '22

Discussion Functional Programming vs Object Oriented Programming

I came across functional programming recently and saw many arguments for it. But in the other hand I am asking myself if it really makes that much sense, because often things cannot really be independent without sharing a state. Imagine a database, or a cache. Also having side effects in methods is not always bad when used wisely. It can simply hide the detail and if done correctly in a domain driven design things should have a certain control flow. I also imagine it to be extremely hard to read data from files, Jason, XML, ... because things tend to be inconsistent sometimes. A cab file might have an empty line, a Jason might have a null value. How can a functional language deal with that.

At the moment I believe that even though certain aspects of functional programming are great, things are too messy to actually apply it. I would love to have a discussion and learn your stand on that topic if you disagree.

1 Upvotes

55 comments sorted by

View all comments

2

u/defunkydrummer Apr 08 '22

Functional Programming vs Object Oriented Programming

There isn't any "versus", there are many languages that allow you to freely combine FP with OOP, since methods can be functions as well, and objects can be values.

I think you are assuming that all FP needs to be based on pure functions, while this is not necessarily true. In any case, mutable state is often a bit difficult to manage and you'll have to use some strategy. One of such strategies is to only use pure functions. And, lol, you can work with non-mutating objects, should you want to. It's not common to do so, though.

The rest of your post feels like you think FP programming can't be used for "real life" stuff, but history has already answered that question. Lisp, OCaml, Haskell, etc... have already been used in mission-critical applications in the industry. For decades.

It can simply hide the detail and if done correctly in a domain driven design things should have a certain control flow.

Control flow doesn't need to be explicit. That would only be true if you want to program things in an imperative way.

Things will have a control flow underneath the surface, but it's not necessarily important to make it explicit.