Today's sample comes from Vasiliy, with no real explanation for where it is, or where it comes from. Frankly though, it doesn't need much setup.
switch (checks) {
case 0:
return new object[] { checkerSummary };
case 1:
return new object[] { "", checkerSummary };
case 2:
return new object[] { "", "", checkerSummary };
case 3:
return new object[] { "", "", "", checkerSummary };
case 4:
return new object[] { "", "", "", "", checkerSummary };
case 5:
return new object[] { "", "", "", "", "", checkerSummary };
case 6:
return new object[] { "", "", "", "", "", "", checkerSummary };
case 7:
return new object[] { "", "", "", "", "", "", "", checkerSummary };
case 8:
return new object[] { "", "", "", "", "", "", "", "", checkerSummary };
case 9:
return new object[] { "", "", "", "", "", "", "", "", "", checkerSummary };
case 10:
return new object[] { "", "", "", "", "", "", "", "", "", "", checkerSummary };
case 11:
return new object[] { "", "", "", "", "", "", "", "", "", "", "", checkerSummary };
case 12:
return new object[] { "", "", "", "", "", "", "", "", "", "", "", "", checkerSummary };
case 13:
return new object[] { "", "", "", "", "", "", "", "", "", "", "", "", "", checkerSummary };
case 14:
return new object[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", checkerSummary };
case 15:
return new object[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", checkerSummary };
case 16:
return new object[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", checkerSummary };
case 17:
return new object[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", checkerSummary };
case 18:
return new object[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", checkerSummary };
case 19:
return new object[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", checkerSummary };
case default:
return new object[] { checkerSummary };
}
If I were to give the developer responsible the benefit of the doubt, I'd think they just heard about "loop unrolling" and decided that they needed to do that for performance reasons. More likely, they forgot loops existed for a brief moment, or couldn't figure out how to pad an array with empty strings using a loop. Which brings us to another question: why is it so important that this array get padded with checkerSummary
on the end? I don't know, but that strikes me as a code smell hinting at other, deeper WTFs.