News for hackers. Stuff that matters.
Re:Admitting that Functional Programming Can Be Awkward by didroe on Tuesday June 16, 2009 @11:54AM (#660374)
Indeed, it might be sometimes frustrating to pass around state that in C would be directly modifiable, but the benefits are huge.

Such as? Ok, so you get better multithreaded behaviour but now you're copying state all the time and having to thread it though all your functions. Sometimes just updating state is the right thing to do.

Personally, I think a good tradeoff is immutable data but mutable references.

Re:Admitting that Functional Programming Can Be Awkward by miloshh on Tuesday June 16, 2009 @12:35PM (#660453)
The main benefit, as I mentioned above, is that if a pure function works once, it works all the time. This is captured by the saying "in Haskell, if it compiles, it works", which is surprisingly often true.

If you have a function that moves a player in a game such as movePlayer :: PlayerState -> PlayerState, you know that it only changes the state of this player, and nothing else. In an OO language you would do something like player.doUpdate(), which has absolutely no guarantees.

Plus there are many facilities available to deal with threading and hiding state.

Re:Admitting that Functional Programming Can Be Awkward by silentbicycle on Tuesday June 16, 2009 @12:45PM (#660480)
> you know that it only changes the state of this player, and nothing else.

This gets ugly when the state of every actor can potentially affect the state of every other actor, though. This is pretty common in games.

That's the main point the linked article is making.

Re:Admitting that Functional Programming Can Be Awkward by miloshh on Tuesday June 16, 2009 @03:11PM (#660706)
Yes, and it is a weak point.

My point, instead, was that FP does not break down when things get ugly; on the contrary, it gives much stronger guarantees on correctness. Of course, it takes effort to express the problem in the more restrictive functional paradigm.

Re:Admitting that Functional Programming Can Be Awkward by ellyagg on Tuesday June 16, 2009 @08:15PM (#661152)
Yeah. I fail to see how scads of global data is less ugly.