Sunday, February 11, 2007

Fucking quirks

In an attempt to make one of my web applications more user friendly and bulletproof it against silly people at the same time, I've been adding Javascript to a lot of the pages. The basic functionality and validation is already there, but I've decided to use Javascript to help make a lot of the repetitive tasks go quicker and generally make the app easier to use:

This means automatically selecting certain options when other options are selected, putting in "Select All" and "Select None" buttons for large lists of items, etc. It's during these times that I've come across (1) one of Javascript's (in particular) little quirks, and additionally (2) a larger issue which affects all scripting languages.

1. In Javascript, when you want to select all the checkboxes (or radio buttons) in a form (or even a particular set), Javascript becomes quite inconsistent: if there's only one element in the group, it returns the element itself, rather than an array. I'll let you mull that over for a couple seconds, then keep reading.


Done ?

Ok. Speaking to any developers out there (or anybody else who's written code) who may be reading this, is that not the most retarded idea ever ? Seriously. That's just asking for trouble and wasting large amounts of time unnecessarily on debugging, especially for somebody unfamiliar with (and trying to learn) the language. Not to mention the fact that it leads to further code cruft due to (in my mind) unnecessary case checking that could be eliminated if something like form.checkboxes or form.radios returned a collection in any case, regardless of how many elements would be in the set. I mean, come on! Admittedly, I've had far less experience than the people who designed and implemented the Javascript language, but I think that kind of design decision is retarded on any level. I'm sorry guys, but it is.

2. While trying to debug the above mess, I came across the larger issue that always affects scripting languages: the lack of strongly-typed objects. By this very nature of scripting languages, this makes debugging harder than any given strongly-typed language, and it sucks. I suppose though, in all fairness to the Javascript language, it's the implementors that are responsible for providing help with debugging. On that note, Microsoft (and Internet Explorer X.X) are horrible for that sort of thing, displaying only "[object]" when trying to put an object to a string. Firefox is a bit better, in fact, it was Firefox that got me through my little ordeal above when I was expecting to see something like "[array]" and it gave me "[object HTMLInputObject]". Thank you Firefox and the developers working on the Mozilla project, it seems like you actually know something and understand what programmers have to go through when debugging things. To the people at Microsoft, how have you not thought of shit like this ? You suck.

No comments: