Last week we saw an attempt to reinvent the `ceil` function. Tina raised a protest: “6 lines to re-implement a ceil function? We can do better.”

``````
public int round1000dSup(int value_To_Round) {
int finalResult = 0;
int resultIntermediate = value_To_Round / 1000;
resultIntermediate += 1;
int valueRounded = resultIntermediate * 1000;
if ((valueRounded - value_To_Round) == 1000) {
finalResult = value_To_Round;
} else {
finalResult = valueRounded;
}
return finalResult;
}
``````

This isn’t a deeply terrible stab at solving the problem. It’s bad, certainly, but it’s not an eye-gouging horror. It rounds up to the nearest thousand. It an odd-way round to get there, but it works.

This method sits in the middle of a 6000+ line class called `Utilities`. It sits next to methods like this one, also for rounding:

``````
public int round100tClose(int value_To_Round) {
int finalResult = 0;
int resultInteger = value_To_Round / 100;
System.out.println("Result integer: " + resultInteger);
int remainderDivision = value_To_Round % 100;
System.out.println("Remainder of division in integer: " + remainderDivision);
if (remainderDivision < 50) {
finalResult = resultInteger * 100;
System.out.println("Final resul in range < 50: " + finalResult);
} else {
int valueRounded = (resultInteger * 100) + 100;
System.out.println("Final resul in range > 50");
if ((valueRounded - value_To_Round) == 100) {
finalResult = value_To_Round;
System.out.println("Final resul on Value already Round: " + finalResult);
} else {
finalResult = valueRounded;
System.out.println("Final resul on value not round: " + finalResult);
}
}
return finalResult;
}
``````

Now, we can see that the comments follow a… convention, of sorts. I like the addition of a bazillion `println`s, which explains a lot about this code, perhaps more than you think.

Tina inherited this project, and the project’s inception was a manager going, “Hey, why should we pay an expensive senior developer to ride herd on a pile of juniors? They all went to college. Let’s just have a team of all juniors doing development.”

This code is clearly someone’s repurposed homework. Sometime during their freshman year, they needed to round numbers, and hacked away until they had this. They handed it in, and probably got a “B”, were happy with the grade and moved onto the next assignment.

There we have it: a giant do-anything class, written by people who are still learning the job, without sufficient supervision, into the wild, until it lands on Tina’s desk, where she now gets to try and clean out the overgrowth and turn it into something maintainable.

“At least,” she adds, “it’s not copy-pasted anywhere else… or is it?”