This page documents cases where I looked at a source code of some software
and totally hated it. I took cases which highlight certain software practices
(that may be even common) that are "The Wrong Thing(tm)".
I don't mind people who don't take the fastest/most readable/most beautiful
approach - you don't have to be a master of programming to write software.
But here you'll find code that is so wrong it screams at you to be fixed
and you want to take the person who wrote it (I shan't dare name that person
a 'programmer'), and bash him/her on the hed several times to get some clue
into them.
Usually its about software managment - people just don't get how much extra
work is done just because the code is a mess and no developer working on the
project can pronounce "software mangment". until its too late, and you're
knee-deep in twisting little source files - and maybe not even then. While there
is something to be said about experience, I know personally some people who
don't get it after doing more then several years of programming.
I came to accept the fact that there are people in the world that would never
know how to code. I'm not talking about writing software - I'm talking about
writing good software.
Email me if you have comments.
Complete lack of proper logging
message_die()
w/o passing any information about
the source of the error except a cryptic message. for example, the code
might look like this: if (!$db->query) { message_die("failed to xxxx"); }Because of the database abstraction layer, they don't have access to the db last error text, so they don't even try.
message_die()
itself is completly broken in that that it calls
external files which on some cases cause it to be recalled. in order to solve that
it defines a global "property" marking it as already called, and it crashes if
it ever sees this property again. since these properties cannot be undefined,
the function can only be called once in a program run. but the function does
not enforce this by shutting the program down at the end, instead it simply
calls exit()
which is also used to exit from include()
directives.Treating include files as subroutines
function this () { // do something // do something else include('external_file.php'); // do more stuff return; }I guess it comes in as some sort of code re-use. problem is - there's very little context in the call, the external file cannot
return
,
readability goes completly out the window, you start getting bits and pieces
of code scattered all over your harddrive and debugging is awful, especially
if you don't have a debugger but uses shotgun debugging like most PHP
developers. its a software management nightmare. Use of loops for no reason (except that the place you copied the code from uses them)
while ($row = $db->sql_fetchrow($result) ) { $somevar = $row['some field']; } // test $somevarThere is absolutly no reason to use a loop here - you only want one value, then do a single read (and check if it fails, of course). Maybe you want just the last value, then format a sort into the query and still only get the first value.
while
to detect the end of input,
and then completly failed to understand the difference between a while
and an if
.
Code duplication as an API