Clojurescript

Clojurescript notebook. Place to capture updated knowledge as I learn.

Synopsis

Clojurescript is a version of the Clojure programming language, which compiles to Javascript. The benefits it brings to the table, apart from the syntax and the style, include the whole gamut of facilities like immutable datastructures, lazy sequences and macros that Clojure provides. Clojurescript, like Clojure, tries its best to leverage the host platform (JVM, or Javascript). So, basic types like strings and numbers directly map to the same types on the host platform, for example. Clojurescript leverages the Google Closure Tools project absolutely, to generate highly optimized and performant Javascript without unduly restraining the developer to any `subset' (read: inferior subset) of the language.

Links

Tooling

For effective use, any programming language needs great tooling support which integrates seamlessly with the most commonly used editors and/or IDEs that developers use. To understand the basics, the Clojurescript Quick-Start Wiki page is a good read, although it does not represent the most popular development workflow. Leiningen, and its huge ecosystem of plugins, support the most popularly used workflows. Boot is another upcoming build tool for Clojure* and claims a better tooling foundation, conceptually and otherwise too. Emacs and vim, unsurprisingly, have various plugins for clojure/clojurescript. Likewise, IDEs like IntelliJ Idea and Eclipse have corresponding plugins. Then there are other newer IDEs/editors (?) like Light Table - you get the idea. Many choices.

The REPL

Unless the REPL is part of your (development) plan, using Clojure(script) would be mostly pointless. Unless you practice guardrail programming, that is. Even then, nothing comes close to the level of fun that REPL-driven development can take you to. TDD is a matter of choice or taste, and can suit some folks more than others. Irrespective of when you write them, tests are, well, gooooood.

The Clojurescript REPL needs a Javascript runtime to evaluate the Javascript code that the Clojurescript compiler (running on the, well, JVM) spits out. There are multiple choices for the run-time. Any browser's JS VM (complicated dynamics, but very commonly used when you are targeting JS in web-pages), Google's V8 Javascript Engine (via Node.js), or Oracle Nashorn (available in JDK 8) are the most standard options. The Clojurescript Quick-Start Wiki is a good starting point to understand it better. It's dense, so going through all the exercises on the page is recommended unless you are familiar with the how-s and what-s.

Description

This section is the most tricky to be written in short. But I'll attempt nevertheless.

We once more invoke the almighty and point you to - The Rationale (The Authoritative Clojurescript Source Wiki) While Clojurescript is different from Clojure, understanding the differences deeper can help you understand Clojurescript itself better. Here you go - Clojurescript and Clojure - Differences