6 ms·
It's funny how async/await has influenced so many other languages but LINQ, that in my opinion is much more interesting (specially the DB stuff) for solving dow
by olmo 10y ago
It's funny how async/await has influenced so many other languages but LINQ, that in my opinion is much more interesting (specially the DB stuff) for solving down to earth problems is sistematically ignored by other languages (Python, Java, JavaScript, etc...)
- ConnorLeet 10y agoArray.reduce(), Array.filter(), Array.map(), in JavaScript are pretty LINQ-ish if you ask me!
- MichaelGG 10y agoThe thing with LINQ is that it can represent itself (reified or 'quoted code), so you can transform it into SQL, GPU instructions, whatever. This isn't a new idea, and F# had it before C# did (and LISP had it before, and others). map/filter/reduce are just basic functional programming elements.
- nightski 10y agoThey are nothing even remotely likely linq. Those functions return the resulting arrays. Linq expressions are not executed until enumerated. This allows you to compose linq expressions without computing intermediate results.
- amyjess 10y agoSounds like Java 8 Streams, then. Streams bear a pretty strong resemblance to translated LINQ.
- louthy 10y agoI guess you can argue that Haskell's do notation is exactly what LINQ (the grammar) is. F#'s computation expressions is a super-charged LINQ also. I would like to see C#'s LINQ get an update. It seems to have been left to rot since Eric Meijer left the team. It doesn't even support the new values tuples where it's been fitted to every other part of the language: from (x,y) in Some((1,2)) // (x,y) will error select x + y; The from x in y, let x = y, where x, select x, and, join x in y on a equals b, could and should be extended. Even better would be to allow custom operators like F#'s computation expressions.
- pbz 10y agoTo be fair, that feature is in the next version of C#; not release yet.
- shitgoose 10y ago.net lambdas are in my opinion cleaner than linq syntax. java 8 implemented lambdas following .net success.
- alkonaut 10y agoLinq is used pretty loosely to include also the equivalent form so dogs .Select(d => d.Id) .Where(d => d.Age > 3) .Skip(4) .Take(2) would be considered just as much "linq" by most c# devs even though this isn't the query language integrated - simply because it's the same exact thing as the regular linq code. I too find the "real" linq form mostly distracting.
- douche 10y agoThe weird SQL-ish query syntax is an abomination. But using the LINQ extension methods, making use of lambdas as you say, is gold. Most of it boils down to plain old functional map/fold/filter/zip constructs under different names.
- amyjess 10y agoIn the case of Python and Java, I think it's because generator expressions and Streams, respectively, accomplish much the same thing. Honestly, if you've seen what LINQ compiles to, it looks an awful lot like a Java 8 Stream. Using Wikipedia's example of LINQ translation (https://en.wikipedia.org/wiki/Language_Integrated_Query#Language_extensions https://en.wikipedia.org/wiki/Language_Integrated_Query#Lang...): Written LINQ is: var results = from c in SomeCollection where c.SomeProperty < 10 select new {c.SomeProperty, c.OtherProperty}; It compiles to: var results = SomeCollection .Where(c => c.SomeProperty < 10) .Select(c => new {c.SomeProperty, c.OtherProperty}); And in Java 8: Stream<> results = someCollection.stream() .filter(c -> c.getSomeProperty() < 10) .map(c -> new AbstractMap.SimpleEntry<>(c.getSomeProperty(), c.getOtherProperty())); (of course, iterating over them is different; you just use a for loop in C#, but in Java you have to either use .forEach() or .collect() to a collection and then for over that) I think Streams have more LINQ in them than most people think. Disclaimer: it's been about a year since I've written Java 8, and this is off the top of my head (and the last time I used it, my employer's codebase had a class for pairs that was better than just SimpleEntry), so the code could be wrong. Edit: and just for completeness... the same in Python generator expressions: results = ((c.some_property, c.other_property) for c in some_collection if c.some_property < 10) Not very LINQ-like, but it serves the same purpose.
- rjbwork 10y agoIn the real world, MOST people are using the "it compiles to" version directly in the code. I certainly don't write the "from x in y select" version, except in the case of multiple hairy joins. Even those have become second nature at this point. It's just more readable, and turns it into an object pipeline/functional programming style instead. The Java 8 streams were pretty much directly taken from LINQ and given their traditional functional names.
- amyjess 10y ago> The Java 8 streams were pretty much directly taken from LINQ and given their traditional functional names. That was my point. I was disagreeing with olmo's suggestion that Java "systematically ignored" LINQ.
- moomin 10y agoFor me, LINQ is fundamentally list comprehensions on steroids. Way better than Pythons, about the same as using list functions in Haskell or F#, Java's finally caught up with its stream library. The LINQ to SQL stuff annoys me, because while it works, it's a painful disaster to implement yourself against your own data stores. Believe me, I've tried.