Lambdas : some good, some very bad..

Posted Wed, Jul 4 2007 13:54 by bill

One of the new things in Orcas is Lambda functions (or inline functions/BLOCKED EXPRESSION.  Although useful because they allow you to write code as one blob, they have some drawbacks :

- code is not factored for re-use

- debugging at best feels weird with them

- performance can suffer

Previously I hadn't really thought about performance until today.  Reading Kit George's latest entry on the VB team blog, LINQ Cookbook Recipe 5, Kit shows two ways of performing an aggregate Concat.  The extension method approach could be improved by using a string builder, but how do you use a String builder when using the lambda approach ?  If you can't then at the end of the day, the lambda ends up creating multiple strings for each concat, and in .NET that's one of the no-no's for writing string concatenation.  The extension method though you can refactor and tune to use a StringBuilder.

Filed under: , ,