综合编程

Should we switch from CoffeeScript?

微信扫一扫,分享到朋友圈

Should we switch from CoffeeScript?
0


A little background

At
nearby.lk
we
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
Forestpin
in early 2014.

Then we replaced all HTML files and generated HTML content in CoffeeScript; initially with
Coffeecup
and then with
Weya.coffee
. 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
TypeScript
.

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", user.name
    @span ".phone", user.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
this
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.

阅读原文...


Avatar

The art of asking questions for developers

上一篇

城堡里学无人机——大疆Mavic设计师回答的正确么?

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Should we switch from CoffeeScript?

长按储存图像,分享给朋友