The Daily WTF
We’ve seen constants in the form of static final int ONE = 1 before. At this point, it’s barely worth discussing, it’s become so common. But Susan has found us yet another unique twist on the subject.
It started when a contractor wrote Java code that looked like this:
String formattedField = fieldFormatMethod(someArray[14]);
The linter complained about the bare literal, so the contractor dutifully replaced it with a constant:
String formattedField = fieldFormatMethod(someArray[XXX_FOURTEEN]);
So much “better”. But note the XXX prefix there. That’s anonymized in this case, but it is a hint to what’s coming. The contractors wanted to make sure they were compartmentalizing their constants, namespacing them “properly”, so guess what happened next?
private static final int XXX_ONE = 1; private static final int XXX_TWO = 2; //etc to private static final int XXX_THIRTY_FIVE = 35; // then… private static final int YYY_ONE = 1; private static final
To read the full article click on the 'post' link at the top.