Why look beyond JavaScript?

A dangerous slope ahead.

“A dangerous slope” ahead.

There are a number of interesting programming languages that you could use in the browser instead of JavaScript. ClojureScript, TypeScript, PureScript, and Elm are some of the prominent examples among many others. The controversial question is: why would you use any of them instead of JavaScript?

After all, JavaScript has good tools and a huge, fast-moving ecosystem. As a language, JavaScript used to be quite awkward, but it has improved a lot in the recent years. Especially ECMAScript 2015 was a great improvement and made JS so much nicer to write.

My answer is that (some of) the alternatives are easier to think about. You can get features like immutable data structures as the standard, static typing, and algebraic data types. All of these help to make the intent of your code clear. They bring crispness to your code.

You can get immutable data structures via libraries for JavaScript (e.g. mori and Immutable.js) and there are static type checkers as well (e.g. Flow). The problem is that they are not widely used. When you want to use third-party libraries, you need convert back to mutable data and come up with type annotations.

The alternative languages can also give you simpler semantics. JavaScript has not been able to escape the complicated this or the uneasy use of objects as maps. Programmers structure their code to avoid the traps, but it’s hard to avoid them entirely. Elm is an impressive example of how you could do something different here.

This is why I advocate alternatives to JavaScript. Coincidentally this is also why I advocate functional programming techniques. Code that is easy to think about has less bugs and is easier to change.


Comments or questions? Tweet to me or send me an e-mail.