The Daily WTF
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.”
//Rounds to 1000d Superior 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 takes 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:
//Rounds to 100d closest public int round100tClose(int value_To_Round) { int finalResult = 0;
To read the full article click on the 'post' link at the top.