News for hackers. Stuff that matters.
Re:“Mostly functional” programming does not work (2014) by TazeTSchnitzel on Monday June 22, 2015 @08:42AM (#9757827)
Mostly functional programming is broken because it cannot solve the problem it sets out to, namely controlling side effects. Because the language type system does not control them, "mostly functional" programming is no more useful than standard imperative programming.
Re:“Mostly functional” programming does not work (2014) by viraptor on Monday June 22, 2015 @09:06AM (#9757974)
I feel like the author makes it easy for himself, by both defining what other languages try to achieve by being mostly functional and how they fail to achieve that. I don't believe he's right with his assumptions.

It's not like linq, Erlang, f#, ocaml, or even python func/itertools designers said - we're going to be as pure as possible and functional to get that almost-purity. Some problems are just easier to solve with functional-like approach. Whether you're doing it in a pure way or not doesn't matter. Some languages give you a way to write that functional-like solution. I doubt many think of purity while using them, but problems get solved. And we're still better off than writing nested loops instead.

For example I'm happy with write:

    items.filter(f1)
        .map(f2)
        .map(f3)
        .reduce(...
and I really really don't need or want an IO monad to be returned from f2 if it happens to need to log some warnings. It would be completely counterproductive.
Re:“Mostly functional” programming does not work (2014) by TazeTSchnitzel on Monday June 22, 2015 @09:56AM (#9758312)
> and I really really don't need or want an IO monad to be returned from f2 if it happens to need to log some warnings. It would be completely counterproductive.

Are you sure you don't? This means that anything calling your function now produces log entries, but it's not obvious without reading its code.

Allowing side-effects saves you time now, but you might hate yourself later when trying to figure out why code in one part of your codebase is magically affecting code in another part.

Re:“Mostly functional” programming does not work (2014) by viraptor on Monday June 22, 2015 @10:07AM (#9758381)
Why should anything calling f2 care whether it can produce a warning or not? If the contract is simple - return a value, then that's all we normally care about.

If logs are not convincing, then think about profiling. One day you want to know what kind of values are computed by some function. Same story: impure adds stats.record(x), pure requires IO redesign.

Re:“Mostly functional” programming does not work (2014) by TazeTSchnitzel on Monday June 22, 2015 @10:12AM (#9758416)
> Why should anything calling f2 care whether it can produce a warning or not? If the contract is simple - return a value, then that's all we normally care about.

What if you call f2 multiple times? What if you call f2 an unpredictable number of times? What if you call f2 in a situation where the logging system isn't initialised?

The parameters and return value are not the only things that matter.

Re:“Mostly functional” programming does not work (2014) by viraptor on Monday June 22, 2015 @10:24AM (#9758498)
Simplest situation in order: multiple logs, multiple logs, default uninitialised log behaviour.

These aren't situations specific to the pure/not issue. You have to know how you deal with them in either case. The uninitialised case it a specific case of: what if your logging target goes away / never existed. Signatures won't help here, because that's a dynamic property of the system.

Re:“Mostly functional” programming does not work (2014) by pka on Monday June 22, 2015 @09:42AM (#9758216)
Just FYI, the author is one of the designers of LINQ.
Re:“Mostly functional” programming does not work (2014) by 1ris on Monday June 22, 2015 @09:46AM (#9758247)
Who says that "Mostly functional programming" sets out to control side effects?

How the hell do you get to the conconculsion that's it's no more useful than standard imperative programming? That implies that e.g. first class functions do not have merit, which is, excuse me, horseshit.

Lisp doesn't do that and it works wonderful. Same for ML/F#, PerformunsaveIO, Ocaml, you name it.

Re:“Mostly functional” programming does not work (2014) by MaulingMonkey on Monday June 22, 2015 @09:11AM (#9758020)
Programmers can control side effects. While mistakes can/will occur, lessening the benefits compared to language enforced control over side effects, there's a big difference between lessening and eliminating. As such, I'd hesitate to say it's "no more useful".
Re:“Mostly functional” programming does not work (2014) by visarga on Monday June 22, 2015 @09:37AM (#9758171)
Mostly functional programming is good enough to make cooperative multitasking and asynchronous programming, which makes for faster servers and easier to reason about user interfaces.

You just have to remember a few globals and try to keep things uncomplicated. Also, having tests helps a lot.