Now That's A Neat Trick was originally published on September 9th, 2006.

Brian was excited to join an organization that boasts managing data for "93% of all health care facility inspections." That's important stuff, after all: inspections are essential to maintaining the integrity of facilities and can make the difference between life and death of its patients. But after eight months working there, Brian now looks for facilities in the "other 7%" for his personal health care needs.

While most companies measure the quality of their product with the ratio of bugs to lines-of-code, Brian's employer uses their own, unique metric called The Cleverness Scale. Utilized primary by upper management (also known as, the Original Coders of the system), code and design techniques are rated as follows:

1 - The Shrug-- Gets the job done, efficient, all that; but just plain boring.
2 - The Nod -- Creative, as in, using a single 32-bit integer variable to store two 16-bit integers.
3 - The Raised Left-Eyebrow -- Very creative, as in, combining all function arguments into a single pipe-delimited string
4 - The "Now That's a Neat Trick!" -- The ultimate in cleverness, as in, code that rewrites itself but maintains the original using generated comments

Despite this scale, most of the developers have actually learned to write code that scores only a 1; it turns out that there's some sort of relationship between clever code and incredibly painful maintenance. Actually, the real problem is when the CTO decides to "take the day off" and join the developers to "show 'em how it's done."

Admittedly, the CTO is able to crush objects and goals in a matter of hours. Granted, his solutions are chock full of bugs, implement a fraction of the requirements, and are generally completely unusable. But as this next example shows, his code always employs "A Neat Trick" ...

$sql = "
       '<a href=\"javascript:;\" onclick=\"'
         + '(\'site_info.php?siteid='
         + 'toolbar=no,menubar=no,location=no,scrollbars=yes,'
         + 'resizable=yes\');\" class=\"siteInfoLink\">'
       ,DATE_FORMAT(insp_date, '%c/%e/%Y')
       ) AS `Inspection Date`
    ,insp_date AS `_realInspectionDate`
       ,DATE_FORMAT(insp_date, '%H:%i')
       ) AS `Inspection Time`
    ,insp_date AS `_realInspectionTime`
    ,insp_requestor AS `Requestor`
    ,insp_originator AS `Originated By`
    ,site_status AS `Status`
    ,site_loc AS `Location`
    ,IF (job_priority IN ('Important', 'ASAP')
       ) AS `Job Notes`
    ,insp_type AS `Inspection Type`
    ,IF (job_priority = 'Important'
       ,IF (o_priority='ASAP'
       ) AS `_rowColor`
  FROM tbl_site_inspections
    INNER JOIN tbl_sites
       ON site_id = insp_site_id

The CTO managed to avoid the Stored Procedures, the Data Access components, the Business Logic components, and smooch SQL, PHP, HTML, and JavaScript into a single statement. A neat trick indeed.

Note to RSS subscribers: to save on bandwidth, I'm moving the RSS Feed to FeedBurner. Please let me know if you experience any disruptions.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!