This is a loosely-connected collection of thoughts stemming from the recent
Strange Loop conference and a book purchase.
BackgroundFor years now, I've known that thoughtful developers:
- separate the JavaScript language from the DOM and wretched browsers
- appreciate JavaScript as a lovely language inspired by (surprise!) Lisp
So, I thought I "got it". Aside from the usual web development, I've even written significant production code in ActionScript in 2003-4.
But I didn't truly learn the language.
It fell into the dreaded
Multi-Month Void of Cognitive Decay (MMVCD).
Here's what I mean: I only faced JavaScript every 3-6 months or so. When it did show up, the situation was urgent, and I felt as though I had to re-learn the basics. Previous 'lessons learned' were quickly lost in the fog of war. I gradually associated the frustration of re-learning with the topic itself.
In this sense, poor JavaScript joined CSS and expense reporting software, falling into the dreaded MMVCD, a random window of cerebral entropy lasting between 3 and 18 months.
(However, even in its worst hour, JavaScript was certainly better than either expense reports or CSS, both of which occupy the darkest corners of MMVCD)
MotivationMany friends have been interested in JavaScript (some in a
career-altering way, no less). Many recommend Douglas Crockford's
JavaScript: the Good Parts. It is mentioned frequently at conferences and user groups.
The tipping point was this review by
Witek Radomski:
I used JavaScript as a garnish for web development... I was afraid of it. I knew I needed to confront the language and learn it properly.
Yow. This person saw into my soul. In fact, that review led to my recognition of the MMVCD.
JavaScript: the Good PartsThis isn't a book review, but: the book is a delight. Minus the appendices, the book is
100 pages in 10 chapters. That is an object lesson for authors and publishers alike! (I would love to know if Crockford faced pressure to add pages.)
What's more, the premise is a winner: a language can contain a beautiful, subset within a complex, (at times) unappealing landscape.
Random Thought #1: Chained DictionariesOn
SE-Radio, someone once joked that Lisp is nothing more than an abstract syntax tree. Funny stuff, and not entirely fair (I believe it is a comic reduction of an earnest point by Paul Graham, though I have no link to support that). Yet there is certainly a grain of truth in it.
My mental model of JavaScript: it has collections of properties. JavaScript does not call them dictionaries; I will. Dictionaries can be chained. A property may be a function. That's it: simple, elegant. Though this is neither fair nor accurate, that idea leaps to mind frequently.
Random Thought #2: Inheritance is an InterfaceScott Bale gave an excellent talk at Strange Loop 2010, based on Crockford's book. During the talk, it struck me: when we learn that a language offers inheritance, it is a fallacy (and audaciously Java-centric) to assume the existence of classes. Classes are merely one implementation of inheritance.
To wit, inheritance is an interface. It is a conceptual contract.
As most will already know, JavaScript offers prototype-based inheritance. This is a different ballgame, but must be understood, if we are to comprehend JavaScript. Crockford banishes the pseudo-class-based inheritance of JavaScript out of the Garden of Good Parts.
(As an aside, Crockford uses the terms 'prototypal' and 'classical'. I think this is a poor choice. To me, 'classical' has connotations of timelessness or an ideal. It took me a long time to realize Crockford doesn't mean to imply that.)
The UpshotIf, like me, you find JavaScript to be in the Multi-Month Void of Cognitive Decay, Crockford's book is a gem. I'll be working through it.
I realize there is now a book on
HTML and CSS, but I don't think I have the stomach for it. Ping me when Expense Reports: the Good Parts is available.
PostscriptBe sure to check out the comments for interesting links on JavaScript material by
Lambda Loungers.