Wednesday, January 28, 2009

Admiring Javascript

I'm at the first Portland JavaScript Admirers, well attended, geeks cheering for CubeSpace. We've got lots of independent contractors, including my Hewlett-Packard friend from Pythoneers (how I'm logged in, wearing the fleece), whom I also invited to our Ruby meetings, first Tuesdays.

We have lots of new immigrants from other states.

There's another guy with glasses across from me into "Django backend, JQuery front end" same thing I'm learning.

Not everyone's an "admirer" yet -- we're free to be skeptics. One guy is up to having a falling out, having been an admirer. We're in all phases.

For those who don't know, Javascript animates your web browser from within, lives in the client, is otherwise known as ECMAscript. It stalled as a language during the lame "browser wars" (Netscape versus Microsoft versus...) but now people praise it, are discovering its true potential, in the form of FOSS toolkits and libraries especially -- what tonight is about.

The Javascript community does have evangelists (no surprise), so more competition for telepreachers of other stripes.

ActionScript, used in Flash, is a close relative of Javascript.

Javascript's "this" invokes in different ways depending on pattern, beware of cluttering your global namespace. Even though 'var' is optional, again you'll be messing with too many globals if you skimp.

Forcing Javascript to act as if it had classes, not just objects, gets gnarly (too clever) IMO. "Prototypal inheritance" leaves me a skeptic, but I still admire Javascript.

SproutCore is client-side MVC
in a browser, not trying to emulate another language, is inspired by Cocoa, Ruby on Rails. Sproutcore is for writing thick (200K?) clients in a browser, but as one page concepts (like Gmail).

Observers, triggered by setters and getters, keep bindings up to date, e.g. take action to update a view.

The function(){}.property() method is similar to Python's, weird syntax though.

To an old dog like me, this feels a lot like working with FoxPro's canned widgets: SC.Grid, SC.SourceListView, Form Controls... Talk JSON to the back end, CouchDB adapter?

JQuery makes it really easy to select DOM elements and manipulate 'em. JQuery is in the same ballpark as Prototype, another JS toolkit. JQuery seems more array-based, so I'm think the J alludes to the Iverson-Hui language (good mnemonics, even if unintended).

Geeks are exuding pleasure about JQuery
, especially the rich library of plugins. Prototype is messier and doesn't support plugins so easily. Prototype provides for richer programmatic stuff whereas JQuery is quite "thin".

JQuery 1.3 is way faster than 1.2, thanks to the reworked CSS selector engine with a Sizzle breakout (Sproutcore might use?), other optimizations. Instead of browser sniffing, it does unit testing to figure workarounds i.e. instead of reading what's on the label, it administers its own tests.

CouchDB is written in Erlang and stores JSON, serves HTTP. "Use this anytime you've been frustrated by SQL". It's based on Mapreduce (shades of OSCON), has a built-in test suite. Each table is a big Btree, schemaless (heresey), ACID compliant. CouchDB's mapreduce is more flexible than Hadoop's. Map is a harvesting, reduce is a processing, often a tallying.