computers/programming languages/Javascript and DHTML


Ajax stands for asynchronous Javascript and XML. It's a set of techniques for building web applications that don't need full page refreshes to transfer data to and from the server. Instead, they package it up as XML, send it in the background using the XmlHttpRequest object, and use the Javascript DOM to load the new data into the page. The result is a web-based application that can support fine-grained interface changes as well as larger-scale page changes, more like a desktop application.

What just struck me is just how similar this really is to a desktop application. The UI runs in code on the client, and only relevant data moves to/from the server. You could almost describe the server as a disk storage abstraction layer.

As soon as web application developers start to realize this, look for some of them to leverage their investments in ajax to turn this web apps into desktop apps. If you're sending a bunch of asynchronous requests, why not just queue them up and send them later when you're connected? If internet bandwidth isn't literally ubiquitous in a couple of years, this will still be a problem worth solving.

If you're a programmer, you are probably at this point thinking, "Shimon, you eeeeeeeeeeediot, you can't run ajax apps offline and queue things up because javascript can't save files." This is really an arcane technical reason, and one that could probably be worked around, but that doesn't actually matter. Javascript can store persistent data on your disk, in the form of cookies. Sure, there are limits to the size of cookies, but you could just generate lots of them—with little cookie allocation tables and parity checksums, like a little cookie RAID storing your to-do list items. Kluge? Hell yeah! This is javascript, after all.

So… keep an eye out for the next big thing: Save-As deployment!

link

My frassle activity has been light lately. I took a small vacation and didn't think much about blogging. Instead, I ate well, slept soundly, and enjoyed the warm (compared to Boston) Cincinnati weather. When I wasn't fully engaged in laziness or family, I was either moving furniture with my California-bound friend Coleman, or programming Javascript.

Yesterday I told Ingo Muschenetz that I had been programming a lot of Javascript, and he offered his sympathies. This is a common reaction: "real programmers" look down on scripting languages, and scripters don't even associate with the losers who write Javascript. Of course, with cool apps and new buzzwords, people are once again stunned at what you can do in the browser, and Javascript is reaching a status not unlike illegal immigrant labor: shameful and abused, but vital to the great stuff coming out of California.

But Javascript isn't all that bad. It's actually kinda nice. While its syntax mostly mimics its namesake, Java, it is in spirit just another dynamic functional language. My personal programming style, developed through Perl hacking and Java schooling, is a blend of object-oriented and functional/dynamic styles. Meaning that I use classes to support modularity and hold state, but use a lot of hashes, lists, and closures.*

It turns out Javascript is excellent for this. In Javascript, the hash (a map from arbitrarily-valued keys to values) occupies a position like the list does in Lisp. Every object in Javascript is a hash, including regular arrays. An object is a hash whose values are either variables or function references. myObj.getFoo() is equivalent to myObj["getFoo"]().

I am not without complaints about Javascript. With some syntactic sugar my programs could be 40% shorter and 20% easier to read, as they would be in Perl or Lisp. With a better and more stable spec from ECMA, cross-browser compatibility wouldn't be as hard. But I also respect that Javascript's priority should be coverage and consistency rather than elegance. Considering that the next feasible choice is Microsoft's VBScript, which would make my programs ten times longer and force me to write sort routines instead of novel UI, I'm impressed. That puts me in the corner with Douglas Crockford, who wrote a wonderful exposition of Javascript way back in 2001.

* Footnote: If you're a Lisp hacker, or just someone who thinks Perl is dirty, I want to understand why you feel that way. Perl has all the important functional features I'm aware of, and if I should really be using Lisp instead I'd like to know. Of course you can write hideous crap in Perl, but it gives the programmer amazing leverage over the language, which translates into huge productivity gains. Is it the punctuation? The diversity supported by the Perl's huge vocabulary? The hackish user community? Or are you just being lazy?

link

Handy tool for web app hackers.

link

An awesome DHTML hack to add column sorting to any HTML table.