Article 72BSJ CodeSOD: A Case of Old Code

CodeSOD: A Case of Old Code

by
Remy Porter
from The Daily WTF on (#72BSJ)
Story Image

We've talked about the For-Case anti-pattern many, many times. And while we've seen some wild variations, and some pretty hideous versions, I think we have yet to see the exact example Ashley H sends us:

for (int i = 0; i < 4; i++) { if (i == 0) { step1(); } else if (i == 1) { step2(); } else if (i == 2) { step3(); } else if (i == 3){ finalStep(); }} 

The specific names of the functions have been anonymized, but this illustrates the key points of what Ashley found.

It's been in the code base for some time, so she's not entirely certain where it came from, or what the company's code review practices were like at the time.

You see, this kind of code doesn't appear fully formed. It gets created, one step, after another, after another, after another. It's like a loop, but... uh... in a line. Without looping.

[Advertisement] Plan Your .NET 9 Migration with Confidence
Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments