We've got to maintain a certain level of 'street-cred'.

Why ClojureScript for websites?

Client-side programming for Web pages is almost synonymous with JavaScript. Every Web programmer knows JavaScript. It's not the only alternative, though. ClojureScript has its own dedicated following, Over a hundred sites use it.

ClojureScript is the client-side version of Clojure, a Lisp-like language designed for the Java Virtual Machine. ClojureScript is essentially the same language, but designed to work with JavaScript and the DOM rather than Java and the JVM. ClojureScript compiles to JavaScript. For some use cases, it has clear advantages over writing JavaScript directly.

JavaScript exists because Netscape told Brendan Eich that his scripting language for the browser should resemble Java. He called that decision "unfortunate" in some respects. His original idea was to implement Scheme, a Lisp-like language, in the browser. Clojure is, in a way, a return to that idea.

Simplicity vs. feature bloat

JavaScript started out as a simple scripting language to add a few features to Web pages. Over the years, it's grown into a fully featured programming language. It's been used to write complete emulators, letting you run a computer in a browser. In the process, it's become a seriously complicated language, with several ways to do everything. Developers who like simple, elegant languages aren't thrilled with it. When programmers with different styles collaborate, the results can be a mess.

Stability

JavaScript follows the ECMAScript standard, and each release includes big changes in the language. Older code rarely breaks, but best practices change with every release. ClojureScript is a more stable language, with a stable API. Developers have reported easy transitions when moving to new versions, usually with no code changes needed.

Immutable data

Clojure and ClojureScript are built on the idea of immutable data. You can build a new data object on an existing one, but you don't normally change one that already exists. Client-side programming depends heavily on asynchronous processes. The client sends a request to the server and waits for a result, but the user may do something in the meantime. Users may click buttons or resize the window at any time, causing a function to run.

Immutability reduces the chances for coding bugs in asynchronous processing. A variable won't mysteriously change because another thread is messing with it. Pages behave predictably.

Functional programming

JavaScript has functional programming, the ability to treat code functions as data objects. Functional programming has become a popular paradigm, especially in asynchronous environments such as Web browsers. It's an add-on to JavaScript, though, not an integral part of the original language. The language is a mix of procedural, object-oriented, and functional concepts. Clojure is based solidly on functional programming. Its name comes from "closure," a key concept of functional programming. It encourages consistently functional design.

JavaScript interoperability

There's a huge amount of good code available in JavaScript, and it wouldn't make sense to cut it all off. ClojureScript can call JavaScript functions, which are accessible through the js namespace. It can access the properties of JavaScript objects and create new objects.

Google Closure

The Google Closure Library is a standard part of ClojureScript projects. Closure is a JavaScript library which provides many widgets, DOM manipulations, and utilities. Its power is always available to developers. ClojureScript can use the Closure minification compiler to reduce the size of the generated JavaScript code.

Why the language matters

Clients ultimately don't care what language a Web page is written in; they just want one that does what it's supposed to. But a language that's clean, one that doesn't clutter the process with ten ways to do the same thing, lets developers focus their imagination on what they can do. It can let them see their way to functionality that they might not have considered otherwise. A language that encourages clean, consistent coding tends to have fewer bugs. Developers who take over a project later can understand it more easily.

From a business standpoint, JavaScript is the safe, conservative way to create client-side code. But for those who are willing to try something new, Clojure is an exciting alternative. It's one of our specialties at TOUCH. Talk with us when you're looking for hand-crafted software for your business.