Thursday, April 24, 2008

A correction

In the recent Bravissimo! post, I included a little snippet of code that looked like this:

if(navigator.appName == "Microsoft Internet Explorer")
{
   httpReq.onreadystatechange = handleAjaxResponse;
}
else
{
   httpReq.onreadystatechange = handleAjaxResponse();
}

Today I discovered (by dint of my usual error-and-trial thrashings) that not only is the browser-check a waste of CPU cycles, but that the httpReq.onreadystatechange = handleAjaxResponse(); code causes Firefox to skip everything after the first onreadystatechange event. Which makes no flippin' sense whatsoever and lowers my opinion of JavaScript even further.

To get around that, I'd included a cheesy workaround in the handleAjaxResponse() function that had it calling itself every second or so to check for the onreadystate's value, plus the value of a global variable or two that prevented it from being locked in an endless loop if the page wasn't found or something else went kerflooey.

But my earlier rant about calling a function (and thus expecting parentheses) stands. It's a function call, not a variable reference, d---it. You can argue GB Shaw's "A foolish consistency is the hobgoblin of little minds" all you like, but computers expect predictability. And so should the programmers who try to make them do their bidding.