The Daily WTF
Sebastian is now maintaining a huge framework which, in his words, “could easily be reduced in size by 50%”, especially because many of the methods in it are reinvented wheels that are already provided by .NET and specifically LINQ.
For example, if you want the first item in a collection, LINQ lets you call First() or FirstOrDefault() on any collection. The latter option makes handling empty collections easier. But someone decided to reinvent that wheel, and like so many reinvented wheels, it’s worse.
public static LoggingRule FindFirst (this IEnumerable<LoggingRule> rules, Func<LoggingRule, bool> predicate) { foreach (LoggingRule rule in rules) { return rule; } return null; }
This function takes a list of logging rules and a function to filter the logging rules, starts a for loop to iterate over the list, and then simply returns the first element in the list, thus exiting the for loop. If the loop
To read the full article click on the 'post' link at the top.