If you are using a loop, you’re doing it wrong

Rather long post by Chuck, but worth reading.

Think about loops and how LINQ changes a perspective on the problem.

Categories: Delphi

3 Comments

Raymond Wilson · Apr 8, 2008 at 22:59

Hi Chuck,

Thanks for the article. While I am not yet involved in using C# or LINQ I can see it is a very
different way of approaching problems.

I will admit to a bad case of syntactic shock when I first saw your last two examples
showing how you put it all together! While my being a neophyte here will explain a lot of it
I do wonder if the intent of the code has not been obscured, at least to the developer other
than the writer who is tasked with doing something with the code. Certainly I suspect LINQ
isn’t an option for reducing the need for comments 😉

Regards,
Raymond.

Serge Dosyukov · Apr 9, 2008 at 00:38

It is more the question to the author.
Along with WCF, WPF and other new things in VS 2005/2008 and .Net 3.x, LINQ is something to keep eye on for sure.

PS. I was just wondering where does Bold/ECO now stand with release of these new parts…

Chuck Jazdzewski · Apr 9, 2008 at 15:09

I believe your shock comes from two places, first, unfamiliarity with the map/reduce pattern this code uses and, second, from a fairly awkward syntax. If a Reduce() call be writen something like,

var ranges = reduce a, b in ranges where a.Style == b.Style select MergedRange(a, b);

it would be a bit more clear but I am stuck with the syntax C# already has.

As for comments. I agree which is why I included them in my example.

Leave a Reply