The Daily WTF
DZ‘s tech lead is a doctor of computer science, and that doctor loves to write code. But you already know that “PhD” stands for “Piled high and deep”, and that’s true of the tech lead’s clue.
For example, in C#:
private List<Foo> ExtractListForId(string id) { List<Foo> list = new List<Foo>(); lock (this) { var items = _foos.Where(f => f.Id == id).ToList(); foreach (var item in items) { list.Add(item); } } return list; }
The purpose of this function is to find all the elements in a list where they have a matching ID. That’s accomplished in one line: _foo.Where(f => f.Id == id). For some reason, the function goes through the extra step of iterating across the returned list and constructing a new one. There’s no real good reason for this, though it does force LINQ to be eager- by default, the Where expression won’t be evaluated until you
To read the full article click on the 'post' link at the top.