> I like to consolidate where possible.
>
> For the same reason to use anonymous functions (at least one of the
> reasons).
Actually I'm all-up for anonymous methods for delegates; agree with
you strongly. Even better in C# 3 where you can use the much
abbreviated lambda syntax.
But there's a line smoewhere, between simpy consolidating, vs
deliberately banging your code out of shape to make it into one line/
statement; the fact that you have to ask how to do it in one statement
probably means you're on the far side of the line. It isn't helping
you, and it can *only* complicate the code. Fine if throwaway, but
most of the longterm cost of code is support/maintenance - which means
(in a typical corporate setupt) that you might not be the person
editing the code next time. If the next person has to stop and think
"what does this do?" then you've achieved an own goal; there are times
when simple code, and meaningful variable names go a long way towards
creating maintainable code.
> It could be that in some cases it is harder to follow by putting 2 anonymous
> delegates in one method call. Not incorrect, just hard to follow.
I agree - not incorrect (see LINQ...) - but I would advocate using
lambdas if possible; they make such things a lot easier to follow;
regardless of the body of the anon/lambda, the human eye/brain can
only see so much at once; a lambda takes only a fraction as much
effort to understand as an anon-method.
Marc
tshad - 28 Feb 2008 06:03 GMT
>> I like to consolidate where possible.
>>
[quoted text clipped - 16 lines]
> when simple code, and meaningful variable names go a long way towards
> creating maintainable code.
Sounds reasonable. If it costs more to put it together and even more to
maintain, then it probably wasn't the best way to go.
>> It could be that in some cases it is harder to follow by putting 2
>> anonymous
[quoted text clipped - 5 lines]
> only see so much at once; a lambda takes only a fraction as much
> effort to understand as an anon-method.
I haven't really done much with lambdas yet, but heard it was pretty neat.
Looking forward to playing with it.
Thanks,
Tom
> Marc