A Case of Old Code

Date:

Share:

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!

Source link

Subscribe to our magazine

━ more like this

The Flats It Girls Are Wearing With Baggy Jeans in L.A.

If you're feeling burnt out about baggy jeans, given how long they've been "in", how about wearing them with something besides sneakers? And what...

Nordstrom Anniversary Sale Haul Try-On

We just did our insane move into our new house (after being displaced for 7 months, ahhhhh!) and lo and behold, a few of...

The Least Reliable AWS Region in 2025

This updated analysis is based on StatusGator outage data collected from January 1 to December 9, 2025. We decided to review our AWS analysis...

Gregory's Meridian Line in Saint Andrews, Scotland

A meridian is a scientific term denoting an imaginary demarcation line that runs north to south and is drawn for astronomical purposes. The...