Tuesday, March 11, 2014

Farting with Code

Agile developers often talk about code smells. I would argue that a code smell can be strong enough to warrant a more pejorative name. I dub such a smell

The Code Fart

Here is a fine example of a programmer passing virtual gas, a real stink bomb:

/*! jQuery v1.7.1 jquery.com | jquery.org/license */
... stuff removed for brevity

 var screenWidth  =  (document.body.clientWidth != '') ? document.body.clientWidth : window.innerWidth;
 var screenHeight =  (document.body.clientHeight != '') ? document.body.clientHeight : window.innerHeight; 

I want to point out what was done here, because most of the stink is non-obvious.
  • Using Apache Multi-View to pretend that a PHP script is actually a JPG file.
  • Using an AJAX get to load an image that is never used.
  • Passing parameters to a GET request that isn't idempotent. It stores the data.
  • Jquery is loaded up on many application pages, and every time it loads - even from the cache - it spuriously dumps an entry into a log table.
  • Hard-coding the domain name. Seriously, who does that now?
  • The most obvious problem: hacking the jQuery distribution file. Seriously? None of this was under source code control system.

This sort of coding is too clever by half and half again. It has the rank smell of putrescine and cadaverine, making me so sick I just had to vomit this posting just to flush it out of my system.

No comments: