Today's Code Snippet of the day is legion. I ran across several snippets that don't necessarily stand on their own, but deserve to be gently* laughed at anyway. We start with a recursive error handler...

I.F. writes, "This might be interesting for discussion. Found in the wild on production system. management summary (in Java) of my investigation of a production bug.
 public boolean aMethod(Object anObject) {
  try {
   /*
    * Some 50 lines of unreadable obfuscated code littered with
    * return statements, throwing some exceptions and performing
    * various exception prone operations like:
    * - parsing
    * - database access
    * - calling other methods of similar signature (but not catching Exception)
    */
   return true;
  } catch (Exception e /*PANIC. NEVER DO THIS AT HOME*/) {
   //call a method of similar signature
   aMethod(anObject); //RECURSION in exception handler => BUG => PANIC
  }
 }

T. M. write, "I'm working with a new PHP based startup run by a few fellows who absolutely hate templating engines. I came across a bit of code that exemplifies this.

function br($count=1) {
    $br = '
'; $out = ''; for($i=0;$i<$count;$i++) { $out .= $br; } return $out; }

Andrew Zhilenko writes, "A new developer was given a task to modify one of the custom modules in our [ticketing system]. When a new ticket arrives during the business hours, it should be randomly assigned to either one of the two available sales persons. The job was reported as being completed, but then something was not working quite right. Investigation showed that the code was as follows:

if ($hour>=7 and $hour<18) {
    # Biff or Cliff
    if (rand() > 0.5) {$Owner->LoadById('70656');}
    if (rand() < 0.5) {$Owner->LoadById('72586');}
}

* By gently I mean, "Let's get the rakes and pitchforks out and go!"