CodeSOD: Constantly Sinister

Cat has some Java code which handles text layout. Now, someone writing the code didn't understand the idea of enumerated types, so every constant is a string.

That's a nuisance, but not a terrible problem. Of course, with Java's String handling, you also run into the fact that == will frequently work, because Java tries to reuse String instances, but it won't always work, and thus equals exists.

So this code didn't actually work:

if (alignment == LEFT_ALIGN) { return RIGHT_ALIGN; } else if (alignment == RIGHT_ALIGN) { return LEFT_ALIGN; } else { return CENTER_ALIGN; }

But even if it did, the only thing I can think when I look at this code is: "No, your other left!"

[Advertisement] Otter - Provision your servers automatically without ever needing to log-in to a command prompt. Get started today!

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published.