Trevor spent a huge amount of time writing a 2,000,000+ PHP/JavaScript/HTML system for an e-commerce company. Like a few other I'm-Special geniuses in our field, he believed that he could do it better than everyone else. For this reason, he came up with his own way of doing things. Database queries. Date-time logic. You name it.

Some time back, Kenzal was brought on as a senior developer to work on the e-commerce system. As he spelunked his way through the system, Kenzal would find some piece of puzzling code and ask Trevor what he was going for, or why he did it that way. Trevor would invariably respond: I had my reasons.

Kenzal encounterd this particular snippet in the "critical logic" in the batch creation process, around 7,500 lines into in the 10K+ LOC invoice manger file, somewhere after running the query and checking for results:

  if ($m == '') $m = 'LLLLSSSSSSSSLLLLLLLL'; 
  $m  = strtoupper($m); 
  $t  = $this->db->getDataset(); 
  $n  = sizeof($t); 
  $sp = 0; 
  $lp = $n - 1; 
  $info = array(); 
  for ($i=0; $i<$n; $i++) {
      $info[$i] = array();
      if (substr($m,$i,1) == 'L') {
         foreach ($t[$lp] as $k => $v) $info[$i][$k] = $v;
      else {
         foreach ($t[$sp] as $k => $v) $info[$i][$k] = $v;
  return (array(0,$info));

Rather than just simply returning the result set, Trevor decided that the results needed to be reordered according to the value of some random string, manually popping and de-queuing the values in the array. When queried as to why he would write something like that, Trevor replied with his usual: I had my reasons.

Both Trevor and his code have since been replaced. When Trevor was asked to leave, he was told (among other things) that they had their reasons. All of the above code has since been replaced with:

`return (array(0,$this->db->getDataset()));`
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!