Saturday, November 7, 2009

On maintaining legacy code

I have been assigned the horrifying task of making some "minor" changes to a "php goo" site.
It is a true horror movie. After reaching this part of code in a file named 'functions.php' (wow informative), I performed the most important refactoring ever.

switch($type){
case 'card':
$filter = ' AND (prdct_productattribute.context = "Card Printer" OR prdct_productattribute.context = "PVC Cards" OR prdct_productattribute.context = "CardReader" OR prdct_productattribute.context = "Hospital Bracelet" )';
break;
case 'bracelet':
$filter = ' AND prdct_productattribute.context = "Hospital Bracelet"';
break;
case 'acc': // !! I hate your coding I hope you die
case 'ribbon':
$filter = ' AND prdct_productattribute.context = "Ribbons"';
break;

Although what you are seeing is only a minor, abbreviated view of the idiosyncrasy abundant in the code base, the author thought it was ok just to drop 2 cases above each other since the 'acc' (which is a parent of the 'ribbon' type) happens to only contain a single child, 'ribbon'.
The refactoring which is the most important is the comment I added. It made me start to refactor the whole thing. I am going to hate myself later on since the pay isn't worth it.
I am leaving the comment in the code base, period.

1 comment: