CodeSOD: Accurate Comments
by Remy Porter from The Daily WTF on (#2YSK)
Kevin L saw the program crash with a null pointer exception. This lead to digging through stack traces, logs, and eventually the commit history to figure out who was responsible.
The code itself is a simple "string padding" function, the sort of thing that when people screw it up, you just have to wonder why. This variation on that theme, however, gives us that rare treat: an accurate comment that describes the function.
// there is a much better way to do this.... public static String padRegistrationNumber(String registrationNumber) { if (registrationNumber.length() == 11) { return " " + registrationNumber; } if (registrationNumber.length() == 10) { return " " + registrationNumber; } if (registrationNumber.length() == 9) { return " " + registrationNumber; } if (registrationNumber.length() == 8) { return " " + registrationNumber; } if (registrationNumber.length() == 7) { return " " + registrationNumber; } if (registrationNumber.length() == 6) { return " " + registrationNumber; } if (registrationNumber.length() == 5) { return " " + registrationNumber; } if (registrationNumber.length() == 4) { return " " + registrationNumber; } if (registrationNumber.length() == 3) { return " " + registrationNumber; } if (registrationNumber.length() == 2) { return " " + registrationNumber; } if (registrationNumber.length() == 1) { return " " + registrationNumber; } return registrationNumber; }
Note: it's an accurate comment. It's still not a useful comment- this function's crapfulness is entirely self-documenting.
[Advertisement] Release!is a light card game about software and the people who make it. Order the massive, 338-card Kickstarter Edition (which includes The Daily Wtf Anti-patterns expansion) for only $29.95, shipped!