Skip to content

Landing Page points

Shaun LeBron edited this page Aug 21, 2015 · 2 revisions

What is this?

ClojureScript is a dynamic language that compiles to JavaScript.


Hold on, before I go any further, is this legit?

The Clojure success:

The Clojure language introduced simple and practical principles to make it an industry success on the JVM. ClojureScript continues this legacy by allowing these principles to reach the larger, ubiquitous JavaScript platform.

Embraces JavaScript:

ClojureScript is designed at its core to be a guest to the JavaScript host platform, meaning easy usage of JS from CLJS and vice versa. This allows the progressive addition of CLJS into any JS codebase, and it allows you to continue taking advantage of the large JS library ecosystem.

Aggressively Optimized:

A fast compiler and runtime tuned for over four years.


Okay, so how and why is it different?

I think I should be to a side-by-side point system to describe each context. They will have to be rewritten and split, but I think the content of each side is there.

Mutability is the new Spaghetti Code:

Unlike Dart and TypeScript, ClojureScript is built on the opinion that dynamic-typing is not the cause of intractable complexity in large programs. Rather, it is the fault of rampant mutability, resulting in our generation's "spaghetti code". Thus, ClojureScript's design focuses on solving the problems of mutability and state.

A new way to see data:

In JS, numbers and strings can never change; all operations on them must produce new values. ClojureScript extends this idea to every value, even collections, meaning that all operations on them must produce new collections. But this is done efficiently through structural sharing, and all operations still comply with the Big-O expectations for the data structure. They are known as "immutable, persistent" data structures and they are embraced as a default idiom rather than an external extension.

Richness of Values (an extension of the previous section actually)

JS data structures are rather restrictive. We cannot write pure functions to transform them cheaply, it is expensive and difficult to compare them, and we cannot use them as keys in objects.

When we think in terms of pure, unchanging values rather than mutable variables, we can write more of our systems with pure functions that are easier to reason about. Furthermore, equality checks for all values become fast reference checks, no matter how nested. And map keys need not be constrained to numbers or strings as they are in JS; any value will do. ClojureScript allows you to think with values, a much closer representation of pure information than the place-oriented model of variables.

Properly Manage State:

Of course there are parts of program ... (flip book model: don't erase, use the next page)

More expressive and consistent syntax:

Most C-style languages like JS have an if-statement and an if-expression (i.e. the ternary operator), two separate syntax shapes and place rules for the same operation. In ClojureScript, everything is an expression of the same shape, each returning a value, and each snapping together however you want, just like LEGOs.

Understanding this syntax is only a matter of realizing that its code is just described in data form, a sort of grown-up version of JSON without commas. Though perhaps jarring at first, removing the parens in an editor reveals it has a rather Python-like familiarity.

Meta-programming

If you are familiar with JSX syntax, that is React's sugar syntax for writing HTML in JS, you will know that it was a controversial syntax addition to JS, now in Babel. But it did address a real need to construct components in JS, rather than resorting to a lesser-powered templating language.

In ClojureScript, there was nothing controversial introduced to meet this need to succinctly construct components in code. A construct,

Furthermore, the syntax supports natural templating using functions already employed in ClojureScript code, a facility not solved in JSX yet.

the syntax is not only simple, but is known for its unbridled power. The syntax can be organically grown through macros. The macro is the notorious footgun of Lisp-lore, but they are generally used by library developers to give application developers the full power of the language. (Golang's goroutines were added as library!)

Simpler, Smaller, and more Robust:

ClojureScript allows you to build simpler, smaller, and more robust programs by creating idioms around the one thing programs are meant create and manipulate: data. These idioms focus you on building systems out of plain, immutable data and pure functions thereof, with an explicit model for managing the stateful, non-pure parts.

Not limiting

Further facilities are provided for imperative styles, creating types/records, polymorphic dispatch, and hierarchical relationships when needed. Schema can be used for runtime type-checking as well.


What else should I know?

  • Google's Production Tools: Though notoriously difficult to use from JS, ClojureScript get the benefits of Google's extensive JS production library/compiler (coincidentally called "Closure") for free. The same stuff used by Gmail, Google Maps, etc. This gives you the holy grail of size optimization by analyzing your entire program and removing code you never use. Never worry about using large libraries ever again.

  • React fully Embraced:

  • Figwheel: The most innovative way to develop with reloadable code.


Is it stable?