News for hackers. Stuff that matters.
Re:LINQ Ruined My Favorite Interview Question by overgard on Thursday July 11, 2013 @10:31AM (#6026210)
LINQ tends to get thought of as "database syntax sugar", but it's way more than that. It's C#'s version of the lazy collection operations you find in most functional languages, just given friendlier sqlish names. (IE, "Select" instead of "map" and "Where" instead of "filter")

I almost feel a bit gross when I have to write a "foreach" loop at this point, because there's almost always an equivalent way to do it in LINQ (although it's a tradeoff, as the one downside of LINQ is that given it's deferred nature, it's harder to debug).

Re:LINQ Ruined My Favorite Interview Question by runT1ME on Thursday July 11, 2013 @05:00PM (#6029204)
>It's C#'s version of the lazy collection operations you find in most functional languages, just given friendlier sqlish names. (IE, "Select" instead of "map" and "Where" instead of "filter")

Actually........

It's more generic than that. It's C#'s monadic comprehension syntax ala Scala's for and Haskell's Do.

It works on more than just IEnumerable, it actually works on anything that implements Select, SelectMany, and Where...

Re:LINQ Ruined My Favorite Interview Question by softbuilder on Thursday July 11, 2013 @10:54PM (#6030653)
This is super obvious if you watch some of Erik Meijer's excellent videos on Channel 9. Recommended viewing for anyone reading this who hasn't. Watching him bounce between Haskell and C# felt like someone explaining etymology by moving between Latin and English.
Re:LINQ Ruined My Favorite Interview Question by MatthewPhillips on Thursday July 11, 2013 @11:07AM (#6026465)
The most annoying thing about LINQ is that they use the SQL language. So unless you use C# and LINQ all of the time it's hard to figure out what functions translate to the ones used by every functional language in the world.

I wish they would at least alias map, reduce, some, etc.

Re:LINQ Ruined My Favorite Interview Question by PommeDeTerre on Thursday July 11, 2013 @06:46PM (#6029783)
Many C# users have experience with SQL, but not necessarily with functional programming languages. The number of these users likely far outnumbers the number of C# programmers who know functional programming languages, but not SQL.

It makes sense to use terms that many C# (and SQL) users are already familiar with, rather than terms that they may not know of.

Re:LINQ Ruined My Favorite Interview Question by dyselon on Thursday July 11, 2013 @09:04PM (#6030265)
I understand the rationale, but in my experience knowing some SQL didn't help me understand LINQ at all. It was only after picking up some functional experience elsewhere and coming back to C# much later that LINQ made sense to me. I'd be really curious to see how the SQLesque naming's worked for others, but it was a bit of a miss for me personally.
Re:LINQ Ruined My Favorite Interview Question by recursive on Thursday July 11, 2013 @02:41PM (#6028191)
You really only have to figure it out once. And for users not familiar with the "standard" names, I think linq's naming is actually more intuitive.
Re:LINQ Ruined My Favorite Interview Question by ajanuary on Thursday July 11, 2013 @04:23PM (#6028950)
tbh I don't think either are particularly intuitive in a "can guess it" sense. Both are intuitive in a "oh, that's what it's called, I can remember that now" sense.
Re:LINQ Ruined My Favorite Interview Question by marcosdumay on Friday July 12, 2013 @12:17AM (#6030887)
Well, SQL is by far the most used functional language in the world.
Re:LINQ Ruined My Favorite Interview Question by chiph on Thursday July 11, 2013 @10:36AM (#6026250)
I do Lazy LINQ, by which I mean I write the looping code with "foreach"es and get it debugged & working, but then allow Resharper to convert it to LINQ if it can.

I think this is mostly because I'm still not comfortable with the syntax, and partly because of the set/iterative impedance mismatch that is there. "It's not you, LINQ. It's me."

Re:LINQ Ruined My Favorite Interview Question by weavie on Thursday July 11, 2013 @10:44AM (#6026305)
You would really benefit from learning a functional language (any) to help you roll your own LINQ. Some of Resharpers refactoring to LINQ is awful and does not make for cleaner code.
Re:LINQ Ruined My Favorite Interview Question by untog on Thursday July 11, 2013 @10:46AM (#6026324)
I almost feel a bit gross when I have to write a "foreach" loop at this point

Agreed. I've transitioned to spending most of my time in JS, and wherever I can I use .map(), but the chaining it's not quite the same as LINQ. Someday I intend to write a library of Array addons to provide GroupBy and so on, but I can't imagine it'll be super efficient.

Re:LINQ Ruined My Favorite Interview Question by PaulAJ on Thursday July 11, 2013 @02:18PM (#6027964)
This is the problem with doing functional list stuff in languages that permit side effects: the order of execution for each function has to be strictly defined (in both senses of the word), so the compiler can't optimise the code. In Haskell the solution (see my comment on the original page) would probably (I haven't actually checked the GHC core output) be folded into a single loop.
Re:LINQ Ruined My Favorite Interview Question by aaronm67 on Thursday July 11, 2013 @05:10PM (#6029252)
In Underscore, you can do something like:

    _([ ... ]).map( ... ).filter( ... ).value()
It's not exactly extending the native array...but there are far fewer side effects to doing it this way.
Re:LINQ Ruined My Favorite Interview Question by WickyNilliams on Friday July 12, 2013 @06:59AM (#6031947)
The problem with this is that it's doing multiple iterations. LINQ on the other hand builds up an expression tree that is "compiled" into a single loop when `ToList()` (or some other method which gets the results) is eventually called.
Re:LINQ Ruined My Favorite Interview Question by alevans4 on Thursday July 11, 2013 @11:18AM (#6026547)
Underscore has groupBy and some of the others you may be looking for.
Re:LINQ Ruined My Favorite Interview Question by untog on Thursday July 11, 2013 @11:19AM (#6026560)
Yes.. I do understand why extending the base Array object in JS is deeply frowned upon but at the same time I often wish that these sort of extensions were on the Array object. It feels clunky to use them otherwise.
Re:LINQ Ruined My Favorite Interview Question by buu700 on Thursday July 11, 2013 @02:09PM (#6027873)
You should check out Sugar, by far my favourite standard JS lib to use in any complex project: http://sugarjs.com/
Re:LINQ Ruined My Favorite Interview Question by WickyNilliams on Friday July 12, 2013 @06:50AM (#6031925)
This may be what you're looking for. I think it was developed my MS specifically for this reason:

https://github.com/Reactive-Extensions/RxJS