Testing Sanity

The core task of software development is sanity testing.

  • warning: Parameter 2 to gmap_gmap() expected to be a reference, value given in /home2/thepalls/public_html/cgpsoftware/includes/module.inc on line 483.
  • strict warning: Non-static method view::load() should not be called statically in /home2/thepalls/public_html/cgpsoftware/sites/all/modules/views/views.module on line 879.

Mootools

05 Nov 2009
Posted by cgp

Ok, so the moral of the story here is this: Don’t determine what version a browser is based on the methods available. I don’t think I was clear about this in the past because I’ve never implemented it myself. What you’re supposed to do is detect whether or not the native functionality exists, if it does, then use it. If not, then either recreate it the functionality or raise an exception (unsupported).

I always thought testing the capability of the browser (instead of using browser version strings) meant conditions like this all over the place before you used the function:

If (window.fancyFunction) {
  window.fancyFunction(
} else {
 doSomethingLikeFancyFunction…
}

But no, what is really done is only done once at the library load:

If (window.fancyFunction) {
  window.fancyFunction(
} else {
 // declare it for use later, now your code doesn’t care what the browser supports
  window.fancyFunction() = function() {
  doSomethingLikeFancyFunction…
 }
}

Of course, this applies to any dynamic language. This might even be considered some form of early binding dependency injection, I dunno. Anyway, time for J’s demo.