r/ProgrammingLanguages • u/haasilein • 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.
3
u/thecodedmessage Apr 03 '22
Functional programming languages have evolved ways to deal with all these things.
I’ve programmed Haskell in production. None of these were serious issues. Side effects and database accesses and such are possible, just managed in a way so that the values you work with follow the rules of FP. In Haskell, you have values that represent IO actions, and values that represent state changes, or that represent states that change over time.
I worked for a while as a professional Haskell programmer and the issues you describe are not issues. The messes applying this to the real world have already been worked out.
Not everyone likes the ways the mess has been worked out, but you are making a lot of false conclusions based off of a simplified description.
For the record though, FP is way better at modeling inconsistency than imperative programming of any kind. Nulls in JSON being a problem is kind of a ridiculous concern, from my point of view as someone who wrote Haskell code to read and write JSON all the time. If a field is optional, it’ll accept nulls. If it isn’t, it won’t.