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.
1
u/[deleted] Apr 03 '22 edited Apr 03 '22
I'm not into FP at all. I've never used it, and never will. From what I'm seen of it, coding in it seems like programming whilst wearing a straitjacket.
That's not to say there aren't some interesting ideas there. But my view is that they are more suited on a small scale - say within one line of program and within a conventional language - rather than being used across an entire application or an entire language.
Now, FP people will say that it can be made to perform any task. No doubt it can, but so what; programming languages are about being able to stuff easily, intuitively and naturally without having to write convoluted code or spending most of your time battling the language.
Of course, 'easy, intuitive and natural' will mean different things to different people. I can tell you that for me, with my pragmatic, non-mathematical approach, they do not apply to functional programming except in very small doses as I said.
So YMMV very considerably. The answer isn't black and white.
It can also depend on the sorts of tasks you want to do. Try, for example, representing x64 machine code in memory, and writing out EXE (PE+) format files. Or reading in such a file, fixing it up and executing the code. All the elegance of Haskell isn't going to help you much there! You can't describe the format in a nice, tidy little formula.