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

I’m going to cure my girlfriend’s brain tumor.

Six months ago, my girlfriend and I were on a beautiful Hawaiian vacation. It was one of the happiest weeks of my life. We...

Gap Jeans Are On Sale— These 16 Expensive Looking Pairs Will Sell Out First

I don't know about you, but I've been on the hunt for a few new pairs of jeans to refresh my wardrobe for 2026....

Summer Fridays SoftLine Lip Liners + Flushed Lip Stains

Summer Fridays added a few new makeup launches to their lineup with lip pencils! They launched a SoftLine Lip Liner Long-Lasting Lip Pencil ($20...

Trump Phone Looks Different, Costs More and Won’t Be Made in the US, Report Shows

Trump Mobile executives have shown off a handset they say is a near-production model of the T1 phone to The Verge, according to a...