November 11th, 2008

Working on the computer, Working

A peek into my past code

I'm looking at some of the code I wrote years ago. I noticed that I was quite anal about my SQL queries. I always used field delimiters (`). On select, update, delete queries on a single primary auto increment column I still used a limit of 1. I did allow queries to all be on one line once I figured it wasn't going to change anymore. I also put the 'AND' of WHERE clauses at the end of the statement instead of the beginning of the next statement.

At some point I made a 'Data Abstraction Layer' (DAL) which could be combined with an extended class. It's sole purpose was to access specific entities by id and cache them. The extended class would define what entities were available as well as do any intermediate data massaging. It passed the data back as an array by reference. This way the receiving end could accept it as a reference and then modify it directly. Once something called the DAL's save method for an entity type it would loop over all rows, determine what rows had been changed or deleted, then update the database accordingly. It was quite a piece of work for 5+ years ago and only using PHP4.

I also made an 'SQL Generator' (query builder). Most of its parameters were specified as an array of arrays, each inner array being the specification for a table/row and some also including more information for comparison to another table/row. The tables required were all listed internally as new tables were requested in the 'where' parameters. The primary reason I made it was so I could modify queries already built depending on what was needed. Looking back on the code I'm not sure if it was a good or bad thing. Compared to the queries I was building it saved some effort and made it easier to copy parameters around to other statements, but compared to the way I write queries now those benefits are somewhat mute.

*shrug*
  • Current Music
    "Light Shine Down" by Collective Soul
Ctrl+Alt+Del - Scott & Ted

Coding pet peeves

I have a number of pet peeves when it comes to coding styles and standards.

One such peeve is when a developer "signs" their change with their name and the issue number. The information is already in the commit message and if I care then I'll annotate and log it. These "signed" comments quickly become outdated and even misleading.

Another peeve is a lack of whitespace between statements, clauses, and parameters. A lack of sufficient whitespace only hurts the programmer when they have to modify the code again.

Smashing elements together on the same line as other elements or the specifier (e.g. array(long ele, long ele)) with no new lines between each element (e.g. array(\nlong ele,\nlong ele,\n)). It's especially annoying if they do some mix of new lines or same line, like the first n or last \n missing. Don't get me started on the middle one missing.

There are others of varying degrees of annoyance.
Ctrl+Alt+Del - Scott & Ted

Misuse of idioms: Clear as mud

Why do people explain something then ask if it is "clear as mud"? The context says they're asking if the person understands what was explained but the words ask if they don't understand it still. If you say 'yes' they think you understand and if you say 'no' they think you don't understand. Stupid misuse of idioms. Stupid stupid stupid.
  • Current Music
    "Addicted" by Enrique Iglesias