Kyle sends us a puzzler of bad code today. It appears in a "JSP-like" codebase- which Kyle provides no futher details on, but certainly hints at a serious WTF underpinning this code.

boolean loop = true;
while (loop) {
    // fake loop to break out of
    loop = false;
    doesStuff();
	moreStuff();
	etc();
}

This is a representative block, as this pattern appears frequently in the code. The comment fake loop to break out of is part of the code- it's copypasted everywhere this particular pattern is used. In no instance is the variable loop ever changed- we enter the loop, set it to false, and then execute our code.

My suspicion about the purpose is that it's meant to easily disable blocks of code- change the first line to boolean loop = false and you effectively skip the block. But if that were the case, a conditional statement would do the job just as well. There's no reason to use a loop. And even if that were the case, that's a huge code-smell, anyway. Is it some misguided attempt at error handling? A misguided attempt at some kind of optimization, somehow? A ritual performed for no reason other than someone decided to do it that way one day, and just kept doing it forever after?

Oh, right, it was written by the kind of person that has a "JSP-like" codebase, implying some sort of inner platform, home-grown, monstrosity. Yeah, that probably explains it.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!