r/programming • • Apr 27 '14

"Mostly functional" programming does not work

http://queue.acm.org/detail.cfm?ref=rss&id=2611829
44 Upvotes

188 comments sorted by

View all comments

-1

u/[deleted] Apr 27 '14

[removed] — view removed comment

7

u/Tekmo Apr 27 '14

Any belief that begins with "people shouldn't do X" is doomed to fail in the large, whether or not it is programming-related. The only things that scale are those that enforce correctness.

-2

u/[deleted] Apr 27 '14

[removed] — view removed comment

2

u/Tekmo Apr 28 '14

It actually has practical consequences. You can't fuse things like filter and map into a single pass over the collection in imperative languages because the compiler can't guarantee that the predicate or mapped function doesn't have side effects. This means that you pay a performance price for the ability to permit side effects even if you never personally use them.

0

u/[deleted] Apr 28 '14

[removed] — view removed comment

2

u/Tekmo Apr 28 '14

Right, but if you wrote that as two separate passes the compiler won't automatically fuse them into a single pass for you. This means that you have to define the entire algorithm in one shot if you care about efficiency, and you can't build it up from separate composable pieces.

0

u/[deleted] Apr 28 '14

[removed] — view removed comment

2

u/Tekmo Apr 28 '14

Interesting. So how does it handle the side effect issue?

3

u/[deleted] Apr 28 '14

[removed] — view removed comment

4

u/Tekmo Apr 28 '14

Thanks! That was really informative! :)

3

u/get_salled Apr 28 '14

The average programmer wouldn't try shoving a print line statement in a predicate for a where clause and care about the order of the output but, unless we have a misunderstanding to what the average programmer is, I would not be surprised at all that they would do something with a side effect that would yield unexpected results when the GT20 check came before all the LT30 checks were completed.

I don't really put understanding LINQ into the realm of the average programmer based on the code samples we require of candidates. Using our candidates as a sample, understanding LINQ is about the 70th percentile of programmers.

I see pseudo-LINQ code often that relies on the fact that .ToList() is called. I'll often rewrite the code to run the foreach so that the enumeration is explicit and obvious because those .ToX() methods often hide in the noise of a single-line LINQ chain.