I'm a bit disturbing that our standards have gotten so low that it requires no less than *six* "constants abuse" submissions to justify a single post. It's a good thing in some ways, I suppose; when you're asked to "look into a little bug in this application," it'll take you that much longer to regret every saying "sure, no problem!"

Our first example is from David who is, admittedly, at fault. They sent business requirements, along with their coding standards, to an offshore coding partner. Among lots of other fun results, they received the following in a shared code file ...

private const int INT_ZERO = 0;
private const int INT_ONE = 1;
private const int INT_TWO = 2;
private const int INT_THREE = 3;
'...
private const int INT_TWENTY_SEVEN = 27;
private const int INT_TWENTY_SEVEN = 28;

There are quite a few who take pride in this approach, though. Josh Buhler's coworker insisted that he was following good practices. In fact, even better than good; he didn't use constants, only local variables in ALL CAPS. That way, if you wanted, you could have FIVE defined as two different values throughout the system.

	var validate:Boolean = true;
	var TWO:Number = 2;
	var FIVE:Number = 5;
	var TWELVE:Number = 12;

	// Name
	var val:String = name_txt.text;
	if (!(val.indexOf(" ")>0) || !(val.length>TWO)) {
		myMessage += "Please fill in your full Name\n";
		validate = false;
	}

	// Address
	var val:String = address1_txt.text;
	if (!(val.length>TWO)) {
		myMessage += "Please fill in your full Address\n";
		validate = false;
	}

	// ...and so on for each field.

Of course, we could all be wrong in thinking that constants named EIGHT are bad. Sometimes, you don't really want EIGHT to be 8, as demonstrated by this code submitted anonymously ...

if (totalGlue > EIGHT) totalGlue = EIGHT;

// burried in a header file ...
#define EIGHT 16

In fact, now that I think about it, maybe it useful after all ... if the rate of the Earth's spin were ever to change, Daniel's coworker would have to only change PAUSE_BY_6_SECONDS from "6" to "6.23" ...

Application.PauseSeconds := PAUSE_BY_6_SECONDS;

Next is from Kyle, who found the root cause behind the failure of long-running daemons ...

TODAY = today()
YESTERDAY = yesterday()
WEEKAGO = weekago()
LASTMONTH = lastmonth()

And finally, Travis was browsing through his Firefox configuration settings, and found this rather peculiar setting ...

general.config.obscure_value = 13

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