Drawing Blanks

Premature Optimization is a Prerequisite for Success

Hitchhiker’s guide to LINQ

leave a comment »

    class Question { }
    static class Earth
    {
        public static string Select(this int source, Action<Question> selector)
        {
            if (source != 42)
                throw new ArgumentException("Wrong answer");
            return "How many geeks does it take to screw in a light bulb?";
        }
    }
 
var q = from answer in 42 select new Question();
 

LINQ in C# is just syntax for calling the “query pattern” extension methods. At first glance, this is striking: the words “select”, “where”, etc. may mean anything. It’s the Enumerable extensions that define the “standard model” which assigns the query semantics to LINQ. But look at operator overloading: “==” can mean anything, “+” can mean anything, and life is not too bad.

Semantics = “antic mess”

Advertisements

Written by bbzippo

01/25/2010 at 6:03 am

Posted in fun, programming

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: