News for hackers. Stuff that matters.
Re:LINQ Ruined My Favorite Interview Question by moomin on Thursday July 11, 2013 @03:40PM (#6028624)
I'm definitely in agreement with the last point. However, I originally said that good C# code contains a lot of LINQ, not that C# code with a lot of LINQ is necessarily good. Deferred execution is something that confuses people, but frankly, it's a concept they need to learn. It's been in the language since yield return got added in 2.0.

LINQ's deferred execution was the right choice for performance, but it's the hardest one. You've got to know when to call .ToList(). I'm not denying that I've seen people evaluate the same expensive list 100 times, use a join when precomputing a Dictionary would have been much faster, close a connection before the result is actually evaluated. But I've never seen C++ programmers say you can make mistakes with pointers, so don't them.

Clojure's lazy sequences are guaraanteed to evaluate once, but that comes at the expense of storage. In particular, a query like the one in the original blog post will evaluate multiple intermediate lists that then need to be thrown away. And indeed, they've introduced reducers to address this, which behaves more like LINQ.

Re:LINQ Ruined My Favorite Interview Question by gngeal on Thursday July 11, 2013 @05:15PM (#6029275)
In particular, a query like the one in the original blog post will evaluate multiple intermediate lists that then need to be thrown away.

Why not fuse the operations, if the values are immutable?

Re:LINQ Ruined My Favorite Interview Question by moomin on Friday July 12, 2013 @01:37AM (#6031110)
Well, there's two ways to do that in Clojure: write your own list processing (usually regarded as bad style) or use reducers. Both are appropriate in specific instances, but the fact remains that the lazy seq code above is the idiomatic way of doing it in Clojure. So the _default_ way of doing it is slower than LINQ's default way of doing things.

It wouldn't be hard to make LINQ behave like Clojure, either.

Re:LINQ Ruined My Favorite Interview Question by tholmes on Thursday July 11, 2013 @04:47PM (#6029126)
Don't forget about Memoize(). Often it can be a better choice than ToList().