You know what I hate pretty much more than any other code nightmare in the world? The hideous waterfall that is PHP! And it’s not so much about PHP because I’ve managed to use it without doing this ever (really). What in the name of all that is cute and cuddly makes a programmer think this is a good idea:
if (some_condition) {
print $header;
print $some_condition;
print $footer;
} else {
print $header;
print $other_condition;
print $footer;
}
Please, please, PLEASE stop doing this!
Here’s a hint:
print $header;
if (some_condition) {
print $some_condition;
} else {
print $other_condition;
}
print $footer;
Ugh! This, more than pretty much anything else, is the single biggest failure of Open Source software. Open Source creates a low barrier of entry, thus allowing anybody to write and publish code. And because said code is mature and relatively bug-free, it is said to “work”, but one of the major tenets of the free software movement is that “If you want to change something, you have the code.” Well, that’s all well-and-good when you want to replace an image or rewrite a string, but it’s a nightmare when you actually want to use the code.
I’ll probably spend the better part of today hacking on this, but I wonder if (in the same amount of time) I would be able to whip something up from scratch that did exactly what I needed and didn’t suck so bad.
And the really bad thing is that it’s a good piece of software — it works and is feature-rich and has a good reputation. But those are all external to code quality (quality as it relates to legibility/extensibility, not functionality).