Thomas P was working on some code a while back where the original developer had devised a "clever" way of encoding errors.

Errors were encoded into a single integer rather than using a Boolean for each error that occurred. A nice way to overcomplicate things, but fine.

As I'm sure you know, this can be achieved fairly straight forwardly by doing a bitwise-AND between a mask integer and your bitmap integer. However, if you're doing this, you want to make the mask integers constants, as to avoid using magic numbers. The original developer understood this, too.

By using constants, you'd expect to see something like this:

private int error; // The current error code.
// Error masks
private static final int ERROR_INVALID_FILENAME = 1024;
private static final int ERROR_INVALID_USERNAME = 2048;
private static final int ERROR_INVALID_PASSWORD = 4096;

But no. The original developer wasn't content 'hard coding' the name of the constants and instead decided to use the following.

private static final int ONETHOUSANDANDTWENTYFOUR = 1024;
private static final int TWOTHOUSANDANDFOURTYEIGHT = 2048;

Needless to say, these constants were not commented so to determine what error they actually indicated one had to dig through all of the code.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!