In an article on the The Dailty WTF, Alex Papadimoulis argues that many programmers write complex code because they are bored. He quotes the book Principals of Program Design which says

“Programmers… often take refuge in an understandable, but disastrous, inclination towards complexity and ingenuity in their work. Forbidden to design anything larger than a program, they respond by making that program intricate enough to challenge their professional skill.”

He gives the following neat trick as an example: some clever CTO has used SQL, PHP, HTML, and JavaScript in a single statement.

$sql = "
  SELECT 
    CONCAT(
       '<a href=\"javascript:;\" onclick=\"window.open'
         + '(\'site_info.php?siteid='
       ,site_id
       ,'\',\'siteW',\'height=480,width=550,status=no,'
         + 'toolbar=no,menubar=no,location=no,scrollbars=yes,'
         + 'resizable=yes\');\" class=\"siteInfoLink\">'
       ,DATE_FORMAT(insp_date, '%c/%e/%Y')
       ,'</a>'
       ) AS `Inspection Date`
    ,insp_date AS `_realInspectionDate`
    ,CONCAT(
       '<NOBR>'
       ,DATE_FORMAT(insp_date, '%H:%i')
       ,'</NOBR>'
       ) 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')
       ,job_priority
       ,''
       ) AS `Job Notes`
    ,insp_type AS `Inspection Type`
    ,IF (job_priority = 'Important'
       ,'#990000'
       ,IF (o_priority='ASAP'
          ,'#330000'
          ,'#000000'
          )
       ) AS `_rowColor`
  FROM tbl_site_inspections
    INNER JOIN tbl_sites
       ON site_id = insp_site_id
";  

Urrgs. Ugly. What a mess. I can’t remember seeing code which is so bad in daily life. Programming is rarely so boring that programmers start inventing problems. Real programmers never do that. There is always an unexpected bug waiting around the corner, and a part of the code which you don’t understand good enough. Programming is a fight against bugs, complexity, and ignorance. If you choose the wrong tool for a problem, you have already lost the fight. The inclination towards complexity comes from the fact that the complexity of the problem often exceeds the complexity of the tool.

Even boring programming tasks can be fun if we try to solve them in an elegant way – with only four lines of code for example. And if we try to improve our knowledge continuously. Constantly learning new techniques and improving your skills is challenging, even if the task itself is boring.

P.S. While editing the post, I just got this message:

Goshdarnit!

Something has gone wrong with our servers. It’s probably Matt’s fault.

We’ve just been notified of the problem.

Hopefully this should be fixed ASAP, so kindly reload in a minute and things should be back to normal.