Should we switch from CoffeeScript?


Should we switch from CoffeeScript?

A little background

moved our backend from python to node.js
and then rewrote both the backend and UI code in CoffeeScript in late 2013. And we migrated all Javascript code to CoffeeScript at
in early 2014.

Then we replaced all HTML files and generated HTML content in CoffeeScript; initially with
and then with
. So we only have Coffeescript and CSS in our projects.

Why we are considering to switch

There are two main reasons. First is that CoffeeScript is untyped. The second is the uncertainty of the future of CoffeeScript.

CoffeeScript is untyped
and so is Javascript. This becomes a problem when you have a large code base. There can be hidden errors not covered by unit tests. Refactoring and making modifications is harder. Also, editors can give better code completion with typed languages. A typed language can introduce extra optimizations too, but I don’t think this is done with likes of

The popularity of CoffeeScript is fading.
There are a lot of posts about people moving away from CoffeeScript, and almost nothing about people adopting CoffeeScript. If CoffeeScript loses popularity there’ll be fewer contributions to the CoffeeScript compiler project; it might not get updated along with developments of Javascript. However, CoffeeScript has so far adopted all new features of Javascript we found to be important (e.g. generators, modules).

What we will miss

We are certainly going to miss

markup in CoffeeScript

. Generating HTML text from Javascript is clean (with string concatenations and HTML tags).

@div ".users", ->
  for user in users
   @div '.user', on: {click: editUser}, ->
    @span ".name",
    @span ".phone",
    if v.image?
     @img src: user.image

The other thing we are going to miss is

executable class bodies

. This let us have mixins, bind
to event handlers
, and even do things like check if all abstract methods are implemented. We use these quite often in our code.

What are we going to do

There was a new release of CoffeeScript, and there are discussions about CoffeeScript2 and about compiling CoffeeScript to ES6. So, hopefully, CoffeeScript will have a future.

Since the only immediate benefit of switching from CoffeeScript to TypeScript is type checking, we will stay with CoffeeScript for a while.

To keep our options open, I started a small side project in TypeScript. Apart from not having a nice way to generate HTML, the experience so far has been good. Typescript is less error prone and the editor code completion saves time. But the code is a lot longer (lines of code) and to me doesn’t look as elegant as CoffeeScript – perhaps I need some more getting-used-to.


Should we switch from CoffeeScript?

The art of asking questions for developers





Should we switch from CoffeeScript?