by Bjørn Storkholm
28. June 2009 17:30
Who can show the worst code ? Recently I ran into something like this:
public string[] GetSomeVeryStupidArray()
{
Dictionary<string, string> customers = GetCustomers();
string[] list = new string[customers.Count];
list[0] = customers[Constants.FirstConstant];
list[1] = customers[Constants.SecondConstant];
list[2] = customers[Constants.ThirdConstant];
return list;
}
private Dictionary<string, string> GetCustomers()
{
string[] customers = new string[]
{
Constants.FirstConstant,
Constants.SecondConstant,
Constants.ThirdConstant
};
Dictionary<string, string> values = new Dictionary<string, string>();
foreach (string name in customers)
{
values.Add(name, name);
}
return values;
}
internal class Constants
{
internal const string FirstConstant = "FirstConstant";
internal const string SecondConstant = "SecondConstant";
internal const string ThirdConstant = "ThirdConstant";
}
Obviously I rewrote this a bit, so I don't offend the person who accually wrote it, but what the f*** is going on ??? I found code similiar to this, in accual production code. The worst part is, that I saw, that some other developer has been copy pasting these methods into new areas of the application we're working on, without even thinking about, what it is he's pasting.... Only two days left...