LINQ has been around for quite a while, making our lives easier with its short, declarative syntax. During talks in closed sessions, the persons behind C# have come up with some great plans for its next version, including some vast improvements to LINQ. The team wanted to make everyone’s lives even better by introducing some ground-breaking features to it.
I’d like to introduce, out of those finalized or at the final draft stage, some of the new keywords that have been introduced to the language with regards to LINQ and by doing so, expose the reader to this new, exciting technology.
Many of the lines of code incorporated into LINQ are about variable validation. How many times have you had to write pieces of code like this:
var values = from n in numbers
where n > 0 && n < 10
This piece of code is very trivial and the compiler is smart enough to understand it on its own. From C# 4.0, the
fine keyword is introduced and the above query will be replaced with:
var values = from n in numbers
where n is fine
Most LINQ queries do not iterate over an entire enumeration. Some filter out results, some use
Skip and other methods in order to run on only a subset of the elements. Since this is an extremely common scenario, the team has decided to integrate it into the language using the new
var values = from n in some numbers
This is complemented with the new
most keyword, which is like
some, only it takes more elements.
from clause is known to all who use LINQ, as it indicates the source of the data. Since this clause is a recurring pattern (statistical surveys have shown it to occur 99% of the time, allowing for a 4% standard deviation), the team behind the new language features has decided to cut it out, thus removing unnecessary verbosity from the language. This, in turn, will cause less characters to be written and rewritten, meaning less keystrokes, less keyboard wear, less purchases of new keyboards, leading to prevention of global warming, a goal near to Microsoft’s heart. You can see Microsoft’s predictions for this in the graph to the right.
This is possible due to the new
somewhere keyword, as described below:
var values = from somewhere
This feature relies heavily upon the newly introduced Type Inference Transfer System (abbreviated MANTA), a technology recently demonstrated by Microsoft Research.
I’ve long since wanted to write a book about something. Since this is just the tip of the iceberg, I’ve decided to write my book about this subject. It will contain most of what I know (hey, I still need to speak about something at conferences and release a second edition some day, right?) about the new language. I think that with all of the new features, making our lives as developers that much easier, I’ve picked an appropriate title.
Here’s an excerpt from the introduction:
Recent advances in compilation technologies have brought with them less need for verbosity. In its stead come smart compilers, which infer much of the work for the developer. With such technology, there’s not a lot you, as a developer, need to do anymore. You can simply write a short statement, validate its correctness, check the code in and go home for the day.
Welcome to the world of tomorrow. Put your feet up.
Here’s the layout of the book, as I plan it:
- New Features in LINQ
What else would you like to see in the book? Let me know and I might just send you a copy of the rough draft for review once I finish it.