The DOM Stigma

by Charles Miller on February 20, 2009

One of the more annoying things about being a Java developer is the stigma the language developed far too early in its existence from being “that Applet language”. You'd mention Java and the first thing that popped into anyone's head was those annoying, out-of-place and usually worthless applications that dotted websites before everyone gave up on Java and turned to Flash for their annoying out-of-place and usually worthless applications. It was unfair1, and I would spend far too much of my time pointing out that when you took Java out of the web browser, it was actually pretty useful.

As such I feel I owe Javascript an apology as, if only through laziness, I have been committing the same sin in its name. When recommending JQuery to co-workers, friends, random passers-by and the occasional hobo (as I have been wont to do recently) I have tended to summarize its merit as “it makes Javascript not suck.” Which is rubbish. Javascript has always been perfectly cromulent. What JQuery does is make the DOM API not suck.

The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page. — W3C

The fatal words here are “language-neutral”. And the particular definition of language-neutral that the W3C uses here is “Java and Javascript”.

The W3C only defines normative bindings for Java and ECMAScript, however we also reference known non-W3C DOM Bindings for languages other than Java or ECMAScript. — ibid.

This is a problem. Java is a strongly and statically typed language with a Smalltalk-style object model. Javascript is a loosely and dynamically typed language with a prototype-based object model. Force them to share an apartment and you've got an instant sitcom. Try to write an API common to both languages and you'll end up having to pick the lowest common denominator.

Which is why DOM manipulation looks like a Java API. Java developers, bless our hearts, are used to the kind of API that requires five lines of code just to populate an array. What JQuery and its ilk do is provide a way of manipulating the DOM that is idiomatic Javascript rather than a strange transplant from another language.

I guess the fact that there is starting to be such a thing as idiomatic Javascript demonstrates if not a maturity of the language, then at least a promising late-adolescence.

1 Java has since accrued more deserved stigmas, but that is a story for another day.

Previously: Have you ever…

Next: Gender, demographics and targeted web ads