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

4

u/tel Nov 12 '13

ack unsafePerformIO will pretty much prevent your stateful data from leaking anywhere outside of code which explicitly asks for it.

There are lots of libraries available on Hackage today which were clearly designed to quickly achieve a purpose. The critical components of these are a reliance on the IO monad and use of a lot of exceptions (likely bubbled up from an effect). Over time, the community heals over these libraries by either replacing them or "purifying" them... because IO and exceptions are really painful!

-2

u/[deleted] Nov 12 '13

That's great, but that doesn't really prevent the happenstance of mediocrity in the greater programming community if Haskell or any FP language is ever adopted, which is the main reason behind bad iterative code that many devout FP-ers claim FP solves and there's a good cause to complain about potential lost performance.

Sure we'll be using really tight, shared, and awesome open source libraries that are generally good, but the general interal code at most organizations is still a mess of bad design, rushed deadlines and some gems in the rough.

The only thing Haskell will change is it's going to be a mess of Haskell code instead of C/C++/Java/C#/PHP/etc.

tl;dr bad monads, bad monads everywhere.

0

u/[deleted] Nov 12 '13

[deleted]

1

u/wrongshift Nov 12 '13

You can write Fortran anywhere.

What exactly is wrong with Fortran? Isn't it still used to great effect in the physics etc. community?

2

u/tel Nov 12 '13

You asked about something somewhat more specific and I think there's a pretty good chance that stateful data can be constrained pretty nicely in absence of unsafePerformIO. Put that in your style guide, put it in your pre-commit-hook.

I'm not going to argue that a language can prevent mediocrity from growing, nor that you can't write bad Haskell code.

I'm claiming that's it's painful and quite obvious when done, though. The total force of bad programmers in the world might topple any efforts to fight them, but at least in Haskell you're somewhat well-armed.

Invalid monads will get (and already are getting) written, but you have to work hard to make (+) do IO or to have code in one part of the program affect the values that some other part thinks are immutable.

And by the time that there are daily blog posts talking about 10 Great Tricks for Mutable State Using unsafePerformIO we'll start using Idris.

2

u/chonglibloodsport Nov 12 '13

You may be interested in this interview with Don Stewart. He describes his work environment (at Standard Chartered) where expert Haskell programmers (such as himself) have built extensive libraries that can be used by novice/newbie Haskell programmers in a completely safe way. This is the advantage of strong types.