Monday, May 19, 2008

How do I say => as used in lambdas

When I did my talk recently someone asked what the predicate c => c.CompanyId == (int) results.Element("ID") meant as they had not seen this syntax before. I explained it was the new lambda syntax in .net 3.5, I tried to read the code out and realised I did not know how to say "=>". I was stumped and it has been bugging me ever since.

I read this blog post this morning Reading Code Over the Telephone by Eric Lippert and he goes some way to helping me solve this riddle.

I personally would say c=>c+1 as "see goes to see plus one". Some variations that I've heard:

For a projection, (Customer c)=>c.Name: "customer see becomes see dot name"

For a predicate, (Customer c)=>c.Age > 21: "customer see such that see dot age is greater than twenty-one"

So taking Eric's advice my predicate would be said like this "Company see such that see dot company id is equal to the results element called ID". After reading the comments I thing I might like this one "Company see is used to evaluate see dot company id equal to the result element ID".

I like the idea that if your code is clear enough to read over the phone to someone then your code must be self explanatory, something to keep in mind when writing code.

I still have a feeling I will have to explain a bit more, maybe not, what do you think? How would you say it ? Is this clear enough ?

No comments: