Re: Community Experience With Iterators vs Overwriting
- From: "Michael Starberg" <michael.spam-captcha.starberg@xxxxxxxxx>
- Date: Fri, 22 Feb 2008 02:37:15 +0100
<jehugaleahsa@xxxxxxxxx> wrote in message
news:e27350c5-6199-412b-9f90-032f2b782e93@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello:
I was running some tests today and found an interesting result. I have
a large library where half the methods work on IEnumerable<T>
(Iterators similar to LINQ), and another that works on List<T>, using
indices to overwrite values.
ok.
I wanted to see which performed better overall (I guessed wrong). What
surprised me what that a well-written Iterator typically ran faster
(usually generating a new IEnumerable<U>) than a similar method that
just overwrites a List<T>.
Good for you.
But what is 'faster'?
Is performance a problem for you?
Does anyone have a good explanation for why this is true?
I have not.
Is it just a fluke on my part? And what does the community say about using
one over
the other?
I say use 'foreach' over 'for'.
Not because one is faster or not,
but just to get rid of the
'i <= list.Length' bugs.
Also it looks nicer. Much more readable.
Also with typing foreach and press tab, you can do a iterator very quickly.
With the common snippet over foreach, with the old snippet started with
'var',
I just had to write my own foreach-snippet, 'fe' that skips that first step.
Don't need to tab through 'var' with my snippet. 'var' is just fine for me
=)
I honestly think there is something beautiful about
Iterators and would like to use them more often than not.
I honsestly also think they are beautiful. May have to do something with
that I actaully have to maintain other peoples code!? =)
The for(init; expression; iter) is HighTech from the -70ies (60ies?). - Move
along folks, there is nothing to see here.. move along...
Thanks for your input,
Use foreach whenever you can.
And Never, Never and NEVER, do a myList.ForEach(lambda => lambda.whatever
== 'something');
... that is just plain ugly!
foreach is your friend!
Travis
Happy Coding
- Michael Starberg
.
- References:
- Community Experience With Iterators vs Overwriting
- From: jehugaleahsa@xxxxxxxxx
- Community Experience With Iterators vs Overwriting
- Prev by Date: Re: Favorite Tutorials for C# 3.5?
- Next by Date: Re: Cannot access HasValue and Value Property of Nullable class
- Previous by thread: Community Experience With Iterators vs Overwriting
- Next by thread: Re: Community Experience With Iterators vs Overwriting
- Index(es):
Relevant Pages
|