Wednesday, December 2, 2015

An Introduction to ClojureScript

Since a few months, more and more developers are adhering to the philosophy of “always bet on JavaScript”. Nonetheless, the number of languages that compile to JavaScript is growing. Some examples of such languages are Dart, TypeScript, CoffeeScript, and ClojureScript.

In this article we'll be discussing ClojureScript, a new compiler for Clojure that targets JavaScript. We'll be looking at the benefits of working with ClojureScript and how you can quickly set it up to use npm and your favorite Node.js libraries.

Why ClojureScript?

There are many articles online explaining the benefits of ClojureScript. Some aggregated high level points are:

  • Simplicity: In regard of the syntax, ClojureScript is a Lisp-based language that gives it a minimal syntax. It's so minimal in fact that we'll be able to cover it in this article. In addition to the simple syntax, ClojureScript also offers tools which help simplify asynchronous code.
  • Safety: This means less bugs! ClojureScript and other functional programming languages have many properties that help reduce and mitigate common bugs.
  • Performance: ClojureScript uses Google's Closure Compiler. This allows ClojureScript to utilize dead code elimination and other features.
  • Live Coding: The ClojureScript ecosystem provides many tools to do “live coding”. This means that once the code is changed, it's instantly reflected in your live project. In this article, we'll be looking at Figwheel so that you can better understand the concept.
  • Code Reuse: ClojureScript can be run universally or, as many say, “isomorphically.” This means you can run the same code on your client and your server. This has become a popular pattern in the Node.js ecosystem. In addition, ClojureScript can import libraries from Node.js and Java ecosystems.

Setting up the Clojure(Script) Tool Chain

In this article, we'll be installing the tool chain on a Mac OSX Environment. The ClojureScript wiki has guides for installing on other environments in case you need them. We'll need a few system dependencies to get started. One of these is Homebrew, the popular OSX package manager.

Continue reading %An Introduction to ClojureScript%


by Kev Zettler via SitePoint

No comments:

Post a Comment