found drama

get oblique

review: ClojureScript: Up and Running

by Rob Friesel

ClojureScript: Up & RunningAn (apocryphal?) tale: 1 when Brendan Eich unveiled the original JavaScript (nee LiveScript, nee Mocha) prototype at (then) Netscape, it was a Lisp. 2 It was only at management’s insistence that the language received a C-like syntax, and even then it was mostly to have some kind of syntactic parity with Java (with which it was supposed to provide some “glue”). Now: if you think about JavaScript using this lens, then it is easy to conjure up images of ClojureScript as “the JavaScript that could have been”. 3

And that is exactly what we have in Sierra and VanderHart’s ClojureScript: Up and Running — a guided quickstart to the language that JavaScript could have been. And what an interesting little language it is!

Sierra and VanderHart deliver an excellent introduction to ClojureScript, which is targeted at a sufficiently broad audience of Clojure developers, JavaScript developers, and developers of all other stripes looking to do some discovery. You don’t need to know Clojure going in, 4 but I suspect you’ll want to know at least a little JavaScript. From there, they take you through installing ClojureScript, installing and working with the Leiningen build tool, the core syntax, and… it goes upward from there. Just as the title suggests: there’s everything that you need to get started. By the time you walk away from the book, 5 you should be able to confidently say what ClojureScript is, what motivated its creation, and you should have enough of the basics down that you could write a trivial application with it. (Perhaps even something more “intermediate” level, if you’re patient and persistent.)

Before we go any further, a few words about what the book is not:

  • It is not a comprehensive language guide.
  • It is not a thorough introduction to Clojure.
  • It is not a primer on JavaScript.
  • It is not a nitty-gritty low-level reference. 6

Now, for as easy as it is to recommend ClojureScript: Up and Running, I did find myself with a few critiques.

First, as someone who likes JavaScript and enjoys writing it, there are some borderline inflammatory statements in here. There’s the line about CoffeeScript having a “cleaner syntax”; and we all know the volumes-upon-volumes of blog posts, forum threads, and flame wars that are already out there about statements like this one. Then there’s that line about how “JSON is a feeble data format”; and I find myself thinking I’ve never felt limited by JSON… These statements read like trolling, and they distract a bit from the salient points being made. (See also: “Stop taking these things so personally.”)

However, this leads me to my second critique: that (again: as someone who lives and breathes JavaScript) the ClojureScript way is not always the JavaScript way, and this seems to be taken for granted in the text. (As an aside: this is perhaps a critique more of ClojureScript than it is of the book.) There is some discussion in the text about how to “marry” these discrepancies, but as ClojureScript is “more strict”, and as ClojureScript is the compiler… it’s the one that “wins” when there is a disagreement. Granted, having gotten through the book, and having grasped the motivation behind the language, I also understand why things resolve in this way — and in light of the idea that “ClojureScript is the JavaScript that could have been”, it’s almost nice to see things resolve this way but… To a self-identifying JavaScript professional, some of this can be a little off-putting. 7

And my last critique: for an introduction, they sometimes drift into almost-but-not-quite esoteric territory without adding sufficient context. Example: “In JavaScript, strings are often used for constants or identifiers in code; keywords fill the same role in ClojureScript.” I read these words, and I understand them. And I believe that I understand the concepts. But I do not believe that I could explain this to someone else. I could not explain why it is important; I am missing some bit of experience or context to bring it fully into focus. There are a handful of these in the book (maybe a half-dozen or so?) but I made a note of them every time: “Come back to this passage after you’ve seen it in the real world.”

Despite these (minor?) critiques, I would easily and heartily recommend ClojureScript: Up and Running to anyone with even a passing interest in learning the language. You may not walk away from the book with a desire to use ClojureScript, but you’ll certainly understand its basics, and at least then you’re forming an informed opinion of it. And this is largely attributable to Sierra and VanderHart’s lucid writing — there is something about Clojure that makes “technical writers” into “better writers”. To borrow from Fogus and Houser: it could be because “Clojure changes the way you think!” 8

Companion reading:

Disclosure: I received an electronic copy of this book from the publisher in exchange for writing this review.

  1. The best source I could come up with to back up my point was this post on Dr. Axel Rauschmayer’s blog. But how much source material do you really need for fun little bits of apocrypha anyway?[]
  2. Or at the very least, it was “Lisp-like”.[]
  3. I wonder: if JavaScript had been a Lisp all along, would we be having the whole “assembly language of the web” conversation at all?[]
  4. Though it might help to have done a couple of the koans.[]
  5. You could read it in a day, but I’d suggest taking your time, and really letting it sink in. Make it two days.[]
  6. That being said, I really felt like the book could have used an appendix or a quick reference for some of those core language features. Not every book out there needs to be Flanagan’s JavaScript: The Definitive Guide (with its hundreds of pages of appendices and dictionaries and references…) – but it’s helpful to get a bookmarkable section like that. (Hmm… what does disj do again…?)[]
  7. Especially when you’re going to call an object (i.e., {}) an “associative array”. That’s a dangerous word in JavaScript land. (I’ve heard them called “objects” and “maps” and “hashes”, but there’s no such thing as an “associative array”.)[]
  8. I wasn’t sure how else to fit in this point, so I’m going to jam it in with this footnote: the real coup in this book, the real “magical moment” was when I got to their discussion of how ClojureScript uses Clojure’s “atoms” as a way of deliberately and purposefully dealing with JavaScript’s otherwise clumsy notion of state as mediated through its global scope. It was like some bright light shone down from the sky and paved the road to enlightenment with parens. That alone is worth the price of admission.[]

About Rob Friesel

Software engineer by day. Science fiction writer by night. Weekend homebrewer, beer educator at Black Flannel, and Certified Cicerone. Author of The PhantomJS Cookbook and a short story in Please Do Not Remove. View all posts by Rob Friesel →

One Response to review: ClojureScript: Up and Running

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*