views:

132

answers:

2

I'm starting to use LINQ as a true query language in code to help improve readability. Until recently I was afraid to touch LINQ because of the LINQ to SQL team move under the Entity Framework team (trying to ignore that conversation here) -- will LINQ the query language be a safe bet going forward (as much as anything in this fast moving industry) ?

+5  A: 

It's worth distinguishing between "LINQ" and "a particular LINQ provider". I think it's safe to say that LINQ itself is here to stay - and it's phenomenally useful for in-process collection processing via LINQ to Objects.

As for which LINQ provider will "win" (if any) - that's a harder bet to call.

I would certainly learn the fundamentals of LINQ itself though - and LINQ to XML is a lovely XML API as well.

Jon Skeet
If LINQ is not here to stay, then you can find me at LINQ's next destination :)
JaredPar
excellent point, i have found it much nicer to read than a for loop followed by a conditional
Toran Billups
+3  A: 

As Jon said it's very important to distinguish between LINQ providers. For instance

  • LINQ to objects: This is based off of IEnumerable<T> and is so ingrained into the BCL that I find it very hard this is going anywhere
  • LINQ to SQL: I don't use this nearly as much as I do LINQ but I know it has a good following and people seem to like it.

Caveat: I worked on LINQ so I'm pretty biased here.

What's really neat about LINQ, at what I think we really got right, is that anyone can write a LINQ provider. All that's needed is a few bindable methods of the right name and suddenly you have query syntax.

var query = from it in someCollection select it.SomeProperty;

I can write this statement without using any of the 3.5 framework. I have my own LINQ Provider which works against the 2.0 framework and is compatible with the query syntax used in the compiler.

I personally lean more towards the lambda/ extension method synatx but the resulting code is really no different.

JaredPar
They don't even need to be extension methods, of course - if you happen to use types which have the right instance methods (or static methods if you're really odd) then query expressions will *still* just work...
Jon Skeet
@Jon, thanks! forgot to mention that. Updated the post
JaredPar
@Jared: Have a look at http://msmvps.com/blogs/jon_skeet/archive/2008/02/29/odd-query-expressions.aspx for some bizarre examples. I do like exploring the corners of a language. Except for generics, where too much exploration makes my head hurt :)
Jon Skeet
@Jon, I have now :). I hadn't ever thought of abusing LINQ via statics and types before. That's a neat concept.
JaredPar
@Jon, my favorite abuse of the compiler is using implicit conversions to create types that widen from a non-generic to any generic value. Useful for a functional style option class in C#/VB: http://blogs.msdn.com/jaredpar/archive/2008/10/06/functional-c-providing-an-option.aspx
JaredPar