Home | Writings | Resume | Links | RSS Feed
A Proud Member of the Reality-Based Community
Like the alignment of the planets, this blog gets updated as I have the time, inspiration, and inclination to do so.
Thursday, January 13, 2005

I just saw this ad online. I assume that it was meant to impress coders, but it had the opposite effect on me. I looked at this ad and I saw seriously broken code.
This code seems to have been meant to look like one of the C-derived object-oriented languages: C++, C#, Java, or JavaScript. It's broken in a lot of ways:
- Confusion between assignment and comparison. The test clause will never work the way it's intended to work. In fact, it's one the most common errors newbie coders make! Instead of
threshold == salary_sucks(comparison)
the code is written
threshold = salary_sucks(assignment)
which will setthresholdto the value ofsalary_sucks, and evaluate to the value ofsalary_sucks. So unlessthresholdandsalary_sucksare both booleans, the code will never compile (ah, the days of C are over), and even if it does, it will generate a warning, because it's usually considered bad style to perform an assignment as a side-effect of a test. (After all, when someone else examines your code later, it's often hard to tell whether that's what you intended, or if you just forgot to type the extra '='.) So, instead of comparingthresholdandsalary_sucks, ifsalary_sucksis a boolean, it will simply branch based on the value ofsalary_sucks. - Reserved word as a variable name.
gotois a reserved word in C++, C#, Java, and JavaScript. No sane coder would use it as a variable name, even in a language where it wasn't reserved, because goto has a long and storied history of controversy. - Evaluation with no effect. Evaluating
suck.it.upwill probably have no effect at all, since it's just evaluating an object member and throwing away the result. If the object member is defined as a getter with some side-effect that is hidden from the caller, that's different, but that would also be really bad style. - Syntax error. There is no
endkeyword in C++, C#, Java, or JavaScript. That's just a syntax error. - Bad Logic. Worst of all, the logic in the ad copy is really broken. In plain English, it says, "If your salary sucks, go to Dice.com. Otherwise, suck it up." But it doesn't make any sense to say "suck it up" to someone who's making a great salary! (does it? Suck up the bucks, I guess...)
if (You.canWriteCode()) {
You.writeCode();
You.salary = BigBucks;
} else {
You.writeAdCopy();
}


