Programming practices that annoy me
Dec. 26th, 2006 10:56 pmA few of the jobs I've worked at over the years have reqired me to maintain code written by those before me. Sure, undocumented code is a pain, but some things end in me shaking my head while muttering "WTF?" to myself over and over.
Here are a few examples:
1) Calling srand() in a for loop. That seeds the random number generator. You don't need to keep reseeding the generator on every iteration of the loop!
2) Writing code like this:
try {
function_call();
} catch (Exception e) {
throw (e);
}
Do you not understand how exceptions work? Throwing an exception you just caught is totally redundant!
3) Writing code like this:
if (condition) {
return (true);
} else {
return (false);
}
return (false);
The astute programmer will note that the final return statement is never reached. Do you not understand how return statements work? o.O
4) Things like this:
$file = fopen($filename);
$line = fgets($file);
Is it that hard to check the return value of a function? Do you like seeing file permission errors all over the webpage? I don't!
Related reading: The Chronicles of George (aka, The System is "Havening" a Problem!)
Also related: The Daily WTF
Here are a few examples:
1) Calling srand() in a for loop. That seeds the random number generator. You don't need to keep reseeding the generator on every iteration of the loop!
2) Writing code like this:
try {
function_call();
} catch (Exception e) {
throw (e);
}
Do you not understand how exceptions work? Throwing an exception you just caught is totally redundant!
3) Writing code like this:
if (condition) {
return (true);
} else {
return (false);
}
return (false);
The astute programmer will note that the final return statement is never reached. Do you not understand how return statements work? o.O
4) Things like this:
$file = fopen($filename);
$line = fgets($file);
Is it that hard to check the return value of a function? Do you like seeing file permission errors all over the webpage? I don't!
Related reading: The Chronicles of George (aka, The System is "Havening" a Problem!)
Also related: The Daily WTF