Thursday, 10 August 2006

Code WTF

My coworkers and I have been seeing an intermittent bug in some new functionality on our customer facing web app. The new functionality basically provided a customer choice for some value added products.

The bug would surface when the web application evaluated for errors (server-side) and made a JavaScript test (client-side) on return for specific customer information then set focus on a radio button.

Up until the new features were added the error quietly failed and caused no problems. But the new functionality provided new radio buttons for customer choice and the JavaScript began exhibiting a hidden, difficult-to-debug, trait: No matter what choice the customer selected, either the radio buttons would reset to none, or would reset to the first choice made by the customer, even if the customer had changed his choice.

When we pointed the Web Developer Tools for Firefox at the problem we could see that name of the feature's radio buttons were being inexplicably set to something not shown in the HTML source.

It took my following the code through the branching and while loops to see the problem. Do you see it too (spoiler follows)?

... form element loop ... 

var currRadio = ""; 

if( currRadio != elem.name ) {
  ...
  if( !checked ) {
    if( elem.name = "residentState" ) {
      setStateFocus();
    } else {
      setFirstErrorFocus();
    }
  }
}

Moral: JavaScript is not a strongly typed language; "objects" have a runtime state moving from boolean to string to number and back again (sounds like another popular scripting language, hmmm...). Be careful of assignment, as assignment will return true, and that evaluates as boolean.

Anybody think this is worth submitting to The Daily WTF?

Posted by caffeinated at 12:38 PM in kaffehaus

Chugging the kool-aid, readying Subversion

Subversion is now installed on my toy rig in the basement. Straight forward via yum.

I built Subversion 1.3.2 from source on my PowerBook. Straight forward, standard autoconf build:

$ ./configure
$ make
<!-- optional $ make check here; I did this, took an hour on a G4 1.6GHz -->
# make install

Options for SSL support, etc. are all documented in configure --help. I choose to ignore the warnings about not having Berkeley DB installed on my Mac. Seems there is a lot of praise for the Subversion FSFS backend, so I'm not going to install BDB to avoid the warning; BDB comes installed on Fedora however, so to use it or not is a switch on the configure script.

Looking forward to playing with the Subversion support in NetBeans on a few small projects I have tabled for too long. 

Posted by caffeinated at 10:33 AM in kaffehaus