8
Kaji
72d

Have some downtime today, so since I lucked out and found some old backups (from before I used Git) of a project I was planning on revisiting, I decided to fire it up and see what I can do to get that going again.

And discovering just how much my coding style has changed since then...

[Code is in PHP, for reference]

* Virtually no documentation (whereas my current style is near-obsessive with PHPdoc blocks)
* Where comments exist, they only use // and are a full tab after the end of the line
* All assignment operators are dutifully aligned on tabs
* Have to update the entire codebase because it relies on deprecated `mysql_*` calls
* Have to flip all of the quotes throughout the codebase because I used double-quotes as my primary at the time instead of single quotes.
* Also relied on magic quotes for injecting variable content into strings
* Associative array practices varied; sometimes the names are encased in double quotes, but I just hit a block where it's all leaving it to the compiler to interpret unquoted string literals

And perhaps the most egregious so far...

* Any time we get database results back the process for cycling through them is to do `$count = mysql_num_rows($result);` (or $count2, etc.), then do a `for ($i = 0; $i < $count; $i++)` (again, or $j, $k, etc.), instead of just a simple `while ($data = $result->fetch_assoc())`

Comments
  • 1
    I deleted some of my first website projects na few summers ago because I was scared to look at the shitfest that was my code

    - I used a fuck ton of &nbsp; to align some words the way I wanted to.
    - Tried to apply CSS to classes I didn't create
  • 1
    Just had the [probably stupid] realization that I probably could have saved myself a whole lot of refactoring here...

    Since the biggest issue is that the mysql_* series of functions isn't defined anymore (since they were dropped from PHP 7), that creates an opportunity to redefine them the way I'm currently refactoring!

    Thus...

    function mysql_query($sql) {

    global $db;

    return $db->query($sql);

    }

    Though, I guess it doesn't quite work with mysql_fetch_assoc()...

    OK, that's enough bad to worse for now. Back to fixing things the right way.
Your Job Suck?
Get a Better Job
Add Comment