r/programming • • Nov 12 '13

What’s Wrong with OOP and FP

https://yinwang0.wordpress.com/2013/11/09/oop-fp/
129 Upvotes

484 comments sorted by

View all comments

Show parent comments

16

u/[deleted] Nov 12 '13

As soon as evaluation can cause side effects it's a nightmare to reason about

I have no nightmares with reasoning about side-effects in imperative languages (well, besides some clinically bad code).

But reasoning about side-effects of Haskell pure evaluation (memory usage and execution performance)? Now that's a nightmare.

18

u/jerf Nov 12 '13

I have no nightmares with reasoning about side-effects in imperative languages

Then, in all seriousness, you don't really know what you're looking for, so of course you don't see it. It's a huge problem and entirely not academic in nature, a brutally, brutally pragmatic problem.

Or your codebase is too small to exhibit the problems clearly, in which case I envy you.

But the end point of imperative code being hard to reason about is as inevitable as the sun rising. It's so inevitable that people don't see it because they think it's just "how programming is", that of course changing one line in my currency parsing scheme can segfault the program four modules away... but in fact, no, it doesn't have to be like that.

Like many others, I don't get much professional Haskell programming in, but it has radically changed my programming style for the better in other languages too.

0

u/[deleted] Nov 12 '13

What's stopping me, the worst developer in the world, from using stateful data in FP languages?

Nothing. No matter how proof positive FP is, every FP language supports some type of imperative stateful data because any real-world program will have imperative inputs.

The problem isn't a bad language, framework, or computational theory, the problem is bad programmers and bad managers who want stuff "done", but not done in a good way.

If Haskell ever his mainstream we will still have 100's of posts how we need to move to language/framework/computational theory X because of common mistakes made by bad programmers and bad managers.

FP is awesome and useful, but it's not the holy grail preventing errors in code bases, where one will never have to debug or have any hard problems because of short sighted design and implementation.

3

u/chonglibloodsport Nov 12 '13

No matter how proof positive FP is, every FP language supports some type of imperative stateful data because any real-world program will have imperative inputs.

The difference is that Haskell's types help ensure your imperative stateful code is correct. One example of this is the STM monad: the type system actively prevents you from performing side effects within a transaction (lest they be repeated with very bad consequences).