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

24 Wholesome Memes Celebrating the Perks of Being a Pawrent

The best part of being a cat pawrent is realizing that life is immediately more entertaining. No matter how ordinary the day is, there's...

Charlotte Tilbury’s New Concealer Dominated the Red Carpet

The secret's out—the number of airbrushed complexions that dominated this year's Golden Globes red carpet finally surpassed the number of dewy-skin makeup looks that...

Fresh Summer Makeup Tutorial – From Head To Toe

This year for me has been a huge process of working hard to keep my skin clear and find routines that are quick, easy,...