Bug Vanquisher

19 December 2007

I Hate foreach

Filed under: Bugz, Dev inside! — Tanveer Badar @ 3:42 PM

There are many reasons. People don’t implement it properly. foreach uses duck typing which does not require one to implement IEnumerable/IEnumerator. But people always go ahead and implement them with "virtual" functions and properties. Consider the performance hit when you are recursively iterating over all the files in a drive.

foreach also requires that collection be not modified during enumeration, yet people still do these kinds of things

foreach( Transaction transaction in transactions )
{

transactions.Remove( transaction );

}

in [it].

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: