Common coding courtesy
The Daily WTF has a really horrendous code example on display. Some consultant decided he wanted to have “fun” while writing his work, so rather than using any reasonable convention for function naming, he just named functions after women’s names. Look at this totally unreadable chunk of code:
int Trisha( int x )
{
int y;
y = TrishaBegin( x );
while ( ! TrishaDone( x, y ) )
{
y = Sally(x,y);
y = Cassie(x,y);
y = Denise(x,y);
// must call Sally again due to head bug [#5518-932]
y = Sally(x,y);
y = Anna(x,y);
y = Beth(x,y);
}
return TrishaEnd( y );
}
How could anyone possibly write that?! That code is unnecessarily hard to edit, and imagine how many clumps of hair that would make a maintenance programmer tear out later on. Frankly, this code isn’t only terrible, it’s cruel and malicious to all of the programmers who will come through after him and work on the same project. At my current job I’m working on some projects where I’m not the first programmer and I know I won’t be the last. It’s a simple common courtesy to the programmers who will follow me to make my code understandable. And I’ve already experienced the benefits myself. Recently I had to go back and fix a bug in something I wrote over a year ago. I didn’t remember a damn thing about any of it, but luckily, since I used sensible names and commented it, I was able to figure it out very quickly.
I’m surprised that the consultant can get away with this without being fired. If I ever caught someone doing this I’d make them fix it on their own time or fire them. There’s only one reason someone would ever do this: to purposefully obfuscate the source code, thus making them “essential” to the company because they’re the only one who figures out how the application works. I can understand being worried about job security, but I think the best way to keep one’s job is to write good, well-documented code, because the second someone sees functions named Anna, Beth, and Cassie, your ass is on the firing line.
January 10th, 2007 at 08:45
I believe the rule is, “write as if whoever’s going to have to maintain your code is an axe-wielding psychopath who knows where you live.”
January 10th, 2007 at 15:05
That’s definitely some good advice to work with. If I came across code like this, I might seriously try to find the identity of the person responsible. Either to ask for some help untangling it … or, your suggestion is good too.