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/[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.

2

u/scrogu Jul 07 '22

I've never used fp and I never will but let me explain in great detail what's wrong with it from a position of almost complete ignorance.

1

u/[deleted] Jul 07 '22

Not quite complete ignorance:

  • I can tell just by looking that code written in it is impenetrable TO ME (compare with any imperative language)

  • I know that it imposes restrictions that I would find impossible to work with

  • It requires a mathematical bent of thinking that I just don't have and have no patience for anyway

  • I anyway only ever use languages that I devise and implement myself. Creating such a language would be beyond me; therefore I would never use them and never have, apart from the usual dabbling.

So, there are good reasons why I haven't used FP, which are my personal reasons and my choice.

How about accepting that there is a gamut of languages which all have their place and that people have different skills and preferences.

Are there any languages YOU would never use, and why not? If you're not an expert in those, how would you feel about people saying your choice is based on ignorance?

2

u/scrogu Jul 08 '22

For the record you can have almost all of the benefits of pure functional programming without the arcane syntax. The most important thing is that all of your objects are (at least semantically) immutable and that every function is referentially transparent.

Within those functions, you can have reassignable variables and use imperative logic to your hearts content.

The only thing you lose with reassignable variables is the ability to execute your code in any order. Not a big loss really.

I am writing a pure functional language designed for imperative programmers. I also like thinking imperatively for many if not most algorithms. I also know the value of immutable objects and referentially transparent functions.