Currently, work has me going through some 10 year-old web applications and changing the code to use MySQL instead of Oracle.
Every so often, I come across just plain bad code. Here’s today’s first example, a SQL statement:
//get highest round $value = $db->getOne( "select value from table where some_id=$id1 and other_id=$id2 and value >= all (select value from table where some_id=$id1 and other_id=$id2) and rownum=1");
Here’s the code after I got done:
$value = $db->getOne( "select max(value) from table where some_id = '$id1' and other_id = '$id2'");
So many times I’ve come across code from programmers who, for one reason or another, have decided that their problem requires a complex solution. And that’s just not the case. There’s usually always a simple solution if you look for it.