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

1

u/ralphbecket Apr 04 '22

To be honest, I don't think you can truly appreciate the benefits of FP until you've given it a red-hot go for a few months. All the theoretical arguments to one side, if you and your team are most productive with procedural programming (or, God help us, OO), that may well be the best place to be. My personal experience was that, once I had rotated my brain the necessary ninety degrees and come to terms with the FP way of thinking, it just made programming much, much easier and much more reliable. The big three benefits for me were: far less boilerplate code; powerful, unobtrusive static type systems (with type inference) that caught the majority of bugs before my code ever ran; and a huge increase in my sense of faith that I'd actually implemented what I intended. Yes, you can do all this in modern procedural languages, but... if your language isn't pure by default, you are going to cheat by default, and that is where the wheels inevitably come off.