Test coverage and dynamic typing

I was bitten by this bug in version 1.9.2 of the Moodle course management system.  It prevented restoring a backup made by any newer version of Moodle. Of course, such a restore could fail if it relies on features particular to the newer version. So there's a conditional that will display a message to that effect, but within the conditional was a typo:

  //We compare Moodle's versions
  if ($CFG->version < $info->backup_moodle_version && $status) {
-   $message = new message();
+   $message = new object();
    $message->serverversion = $CFG->version;
    $message->serverrelease = $CFG->release;
    $message->backupversion = $info->backup_moodle_version;
    $message->backuprelease = $info->backup_moodle_release;
    print_simple_box(get_string('noticenewerbackup','',$message),
        "center"", '', "20", "noticebox");
  }
In other words, by trying to warn the user about possibly erratic behavior, it caused definite failure.  :)

It's dreadfully familiar, isn't it?  Just a throwaway conditional that you assume will work without sufficient testing.  Just a fault that slipped into a point release and was fixed in the next one.  Not a big deal, but there's a lesson here.

My position on the static/dynamic typing divide is well established, even though I'm not as entrenched as some.  I will somewhat happily use Python or PHP for web applications.  I advocate for Scheme, and I think Ruby is neat.  But I'm still disappointed whenever I produce or find faults that by all rights should have been caught by a compiler.  It just demonstrates the increased importance of automated testing with coverage analysis when using dynamic languages.

©20022015 Christopher League