Monday, March 29, 2010

Sad but true joke about the world we live in...

From Pippa Sibley's column: Language of hope shows world divide


The UN sent a survey to the member nations with the following question: "Would you please state your honest opinion about the solution for the food shortage in the rest of the world?" Instead of responses, they received requests for clarification because nobody understood all the words in the question:

* African nations didn't understand the meaning of "food"
* Western European nations didn't understand the meaning of "shortage"
* Eastern European nations didn't understand the meaning of "honest"
* China didn't understand the meaning of "opinion"
* Middle Eastern nations didn't understand the meaning of "solution"
* South American nations didn't understand the meaning of "please"
* The United States didn't understand the meaning of "the rest of the world"

Friday, January 8, 2010

The most arcane bug of them all... Divide by Zero

It's interesting that even in modern times we still encounter the dreaded Divide by Zero error. I stumbled across this error recently in the Scriptaculous slider library.

There it was waiting to pounce from line 153 in the slider.js file upon any unsuspecting code that so happened to call the translateToPx() function. Here it is exposed to the harsh light of day:

  translateToPx: function(value) {
return Math.round(
((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
(value - this.range.start)) + "px";
}


There! There is the beating of it's hideous heart! For if a slider is initialized with a range whose start value is the same as its end value a most wicked zero is spawned from hell and possesses the denominator. IN THE NAME OF ALL THAT IS GOOD I CAST YEA BACK INTO THE HELL OF COMPLEX NUMBERS!

  translateToPx: function(value) {
try {
return Math.round(
((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
(value - this.range.start)) + "px";
} catch (e) {
return "0px";
}
}


http://prototype.lighthouseapp.com/projects/8887-script-aculo-us/tickets/154-0-range-slider-causes-ie-error