5 ms·
I used to work in C# (now mostly live in JavaScript land) and I miss things like LINQ a lot. So here's hoping we see wider adoption of C# in the future.
by untog 12y ago
I used to work in C# (now mostly live in JavaScript land) and I miss things like LINQ a lot. So here's hoping we see wider adoption of C# in the future.
- troycarlson 12y agoI spend most of my time in C# and it's always a sad moment when I start typing .Where(x => ...) in another language and realize it doesn't exist.
- frou_dh 12y agoIt's spelled filter http://en.wikipedia.org/wiki/Filter_%28higher-order_function%29 http://en.wikipedia.org/wiki/Filter_%28higher-order_function...
- untog 12y agoI don't mind C# not using that name because .Where doesn't actually filter the object, it returns an IQueryable, which you can chain further statements onto, then filter.
- DennisP 12y agoThat's basically what filter does in Clojure (and probably any other language with lazy evaluation): http://debasishg.blogspot.com/2010/05/laziness-in-clojure-some-thoughts.html http://debasishg.blogspot.com/2010/05/laziness-in-clojure-so...
- _random_ 12y agoNah, it's spelled Select: http://www.w3schools.com/sql/sql_where.asp http://www.w3schools.com/sql/sql_where.asp (but academics like non-human-friendly terms, sure)
- frou_dh 12y agoNo idea what point you're trying to make. On human-friendliness, filter can read as a physical metaphor, so scores rather well. Just need to remember whether what's caught is kept or discarded.
- seanmcdirmid 12y agoNo. Select == Map Where == Filter SelectMany == FlatMap Aggregate == FoldL
- taco_emoji 12y agoNot sure why this is getting downvoted, that's what it's called in most other languages.
- antics 12y agoThe LINQ API is modeled after relational algebra (where `Select` acts as projection, and `Where` acts as selection, etc.), which is as good a basis for operations on collections as anything. It is not even clear that other popular names have precedent, let alone especially useful expressive power beyond what normal relational algebras afford. Besides that, one of the early intents behind LINQ was to allow a language-integrated ORM, so LINQ's choices for names are actually extremely appropriate.
- frou_dh 12y agoThe comment replied to was about missing its like in other languages. Didn't mean to imply that its name should be changed in C#.
- dingleberry1j 12y agoEven c++ has lambdas now... what's the big deal again?
- emodendroket 12y agoIt's pretty trivial to implement Linq-like functions in JavaScript, or, I think stuff like undersocre has them.
- untog 12y agoIt is and it isn't. LINQ is actually incredibly smart under the hood, so if I ran: myList.Where(x => x.name = 'Person'); .Where(x => x.age > 18); .ToList(); it wouldn't actually run two different array filters - it would combine them. You can imagine the performance gains to be had there.
- emodendroket 12y agoWell, underscore offers this, from the docs: _.where(listOfPlays, {author: "Shakespeare", year: 1611});
- mynameisvlad 12y agoThat's not the same, though; that's you purposefully combining your query (which you can do in LINQ). LINQ doesn't just combine Wheres. It tries to optimize your query as much as possible and executes lazily, so you aren't actually doing any work until you try to use the resultset (in a ToList, for example).
- Todd 12y agoYes. IQueryable actually implements an expression tree, which means that it may never be executed, at least directly. LINQ to Entities (Entity Framework) actually evaluates the expression tree to build SQL statements, then runs those and returns the results (after coercion back to the mapped POCO object).
- emodendroket 12y agoRight. Actually Linq to SQL did the same thing, but a big philosophical difference is Entity will reject stuff that it can't resolve from the database instead of just letting you do whatever (which may involve multiple queries).
- rjbwork 12y agoI'm primarily a C# guy, but whenever I touch JS, i find Underscore indispensable.
- rjblackman 12y agoperhaps these two projects would interest you? https://linqjs.codeplex.com/ https://linqjs.codeplex.com/ http://underscorejs.org/ http://underscorejs.org/