Geoff Pado

ClojureScript & Om

For a while now, I’ve been looking for a functional language that I like enough to use on a regular basis. It’s pretty clear that functional paradigms will only become more important in the near future due to the inherent concurrency and parallelism wins. I’ve bounced around between a few well-known functional languages: Haskell, Scheme, Clojure, and even a brief flirtation with F#.

I certainly didn’t expect the language I ended up loving to be one that compiled to JavaScript.

However, I’ve been playing around the last few weeks with ClojureScript, and it’s easily been the best experience I’ve had so far with a functional language. With every other functional language I’ve tried, there was always a nagging sense that it wasn’t really helping me; everything I was doing in those languages was easier and more expressive in Ruby. The “wins” of functional languages just weren’t important in the kinds of work I was doing.

ClojureScript, however, doesn’t compete with Ruby. It competes with JavaScript, and there, the benefits of FP really shine. I can’t throw more processes at JavaScript the way I can with a Ruby service (via something like Unicorn). I can’t easily split a JavaScript “app” into multiple services to best handle individual pieces. And personally, JavaScript’s syntax just isn’t anywhere near as nice as Ruby’s.

One of the things that drove me to ClojureScript in the first place was Om, a ClojureScript front-end to Facebook’s awesome React framework. React, as its name implies, is a framework to create reactive views in JavaScript. React allows you to build views in the DOM made up of components that render based on a given state.

I’d played with React before, just to get a feel for it, but it always felt shoe-horned into JavaScript, a language that didn’t really match the feel of React’s FRP paradigm. Heck, Facebook had to create a new templating syntax to represent the kinds of tree structures that the DOM represents. Om fixes this. With ClojureScript being a Lisp-based, functional language, it feels like React was built to be used in this language. S-expressions fit React’s virtual DOM in a much more coherent manner than anything JavaScript (or even JSX) can provide.

I’m still working on my first “real” ClojureScript project (an update of WWDC Parties, the same project I’ve used to learn everything I know about web development), so I’ll likely post more about my experiences as I work through that.