Index
- What is wrong with this code? Part 1.
- What is wrong with this code? Part 2.
- What is wrong with this code? Part 3.
Introduction
Recently I participated in the interview and one of the questions reminded me about the situation I was part of a long time ago. At that moment I was working on the backend Web API to process datasets of various sizes – string from 1.000 to 100.000 items.
One of the processing steps was to group items by key.
Let’s imagine a DataItem
class…
public class DataItem
{
public int Key { get; }
public string Value { get; }
public DataItem(int key, string value)
{
this.Key = key;
this.Value = value;
}
}
… and the code I wrote was something like this:
DataItem[] items;
// more...
this.items.GroupBy(i => i.Key)
Usually when we think “How good this code is?” we’re trying to rate it*:
- Usage of TABS vs SPACES
- Class, Methods, Locals naming
- Code Style
- Readability & Maintainability
- Performance (time to execute, memory consumption etc.)
* the items are placed in order of importance.
While all of the above is really important let’s try to analyze code from Performance point of view.
So… What is wrong with this code?
Continue reading “What is wrong with this code? Part 3.”