Ballywoo Blog

Art of Woo

LINQ to Woo: Notes and Thoughts on Bart De Smet’s LINQ, Take Two – Realizing the LINQ to Everything Dream

I had the pleasure of attending the Microsoft Professional Developer Conference 2010 viewing and sandwich giveaway at the Mothership offices in Midtown this week. High on everyone’s viewing priority (and mine) was Bart De Smet’s LINQ, Take Two – Realizing the LINQ to Everything Dream.  A link to the session is provided at the end of this article.

If you have coded with LINQ before then you can probably identify with the title. Once you’ve ‘LINQed’ to a provider (especially to SQL/XML) and queried it in native C# syntax you will want to LINQ to everything under the sun. You’ll be passing lambdas at the dinner table when you want mashed potatoes.

At Ballywoo, our codebase makes heavy use of LINQ. This allows us to easily query in-memory collections and Mongo repositories using simple lambda’s as predicates. Moreover, LINQ looks good. As we attempt to internally promote and maintain the use of our Domain Specific Language(DSL), LINQ allows us to make semantic sense of our model. Check the difference as I attempt to find my golden retriever:

Non-LINQ, non-enumerable, non-DSL:

private Animal FindAnimal(IList animals)
    for (int i = 0; i <= animals.count; i++)
        If (animals[i].Type == “Golden Retriever”)
            return animals[i];


private Dog FindDog(IList dogs)
    return dogs.Where(d => d.Breed == “Golden Retriever” ).First();

Though functionally identical, the second example is much more readable and concise.  If that looks new and appealing to you, immediately drop what you’re doing and start looking into LINQ. Hopefully though, you’re already wrist deep into LINQ-based development and looking to improve your skillset – my approach prior to viewing De Smet’s talk.  Let’s go on a quick research walk and you can know what I know:

First, some background on De Smet himself. You can check out De Smet’s blog here.

Prior to viewing the PDC session I read the following article, which illuminates a lot regarding LINQ under the hood. If you haven’t had a comp-sci class in a decade, read it a few times until the concepts start to take hold. De Smet’s talk is fairly academic. You’ll want a solid understanding of terms and concepts prior to viewing.

The session itself was very engaging. In part De Smet summarized a few blog articles he had already written (see above).  He discussed heavily the notion of LINQing to collections utilizing the new Reactive extensions(Rx), which I am sure we will all be utilizing heavily once patterns involving C# 4.0 technologies become more ubiquitous. This included LINQing to observable collections which push data asynchronously rather than a one shot pull. For example, each time you query a stock index collection it will already contain updated results. He took the idea further with the notion of Qbservable (no, not a typo), where the collection subscription is invoked with a query (so rather than filtering from the entire result set the collection is ‘prefiltered’).

One very cool example De Smet provided involved LINQing to Z3 to solve a Sudoku puzzle! You can find that code here. (Regarding the example: No, I don’t know how “esoteric LINQ bindings” are analogous to Deoxyribose but feel free to read this and let me know in comments below.)

The entry on Sudoku lead me down another interesting trail when De Smet mentions using MGrammar to parse out hand-written puzzles (rather than initializing them as code). M is here, sort of, though all links point you to this poorly maintained blog for current M info.

The fact that our walk began with LINQ and ended with M (via Rx and Z3) is indicative of how deeply the technology can reach. LINQ has the ability to transform and improve the way we carry out many operations as developers, and allows us to easily tap into new and complex collections. A future blog entry is definitely in order regarding the use of M/MGrammar, or some such DSL library. For now, enjoy the video!

Link to the full PDC2010 session.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: