JavaScript is a mess. And using a compile-to-JS langauge is an interesting approch to fix it. Recently I had a simple JavaScript homework, and that was a great chance to try few compile-to-JS langauges. The homework was too simple that I wasn't able to try out all features of the languages, but it was already fun enough.

Source code here: https://github.com/b123400/csci4140-youtube-remote

ES6 + Babel.js

Well, it is JS, the future one.

  • It is still JS, weird things still happen. So don't look for magic.
  • Syntax improvements are nice
  • Arrow function => and let make things cleaner. I find myself don't need a new this for functions except for class methods, and with the help of class syntax, the whole document is now free of function!
  • Generator and Iterator are cool, sad that I don't have chance to try it out :(

Generally a better version of JS, not ground breaking. Looking forward to what can kind of good use can the community comes up with iterator and generator. Flow control should be more interesting when ES6 is popular!

TypeScript

  • JS + Type
  • Safe to do it, very good approach to make JS more maintainable.
  • You can switch back to JS anytime, just why not give it a try?
  • Typing is optional, so you can start immediately.
  • In order to fully utilize typing, it's recommended to define types for external codes you use, and that can takes time.
  • Luckily there are lots of people doing this, e.g. jQuery

A very safe approch to improve JS, especially for people who want to make their code safer but don't know where to start with. It takes longer time to code in TypeScript, but it's worth. You can check Facebook's Flow for typing JS as well.

Haxe

  • A langauge that compiles to JS, not that close to JS
  • More structural, strictly OOP
  • Objects are strictly typed, and you have to follow Haxe's way to do things, e.g. you'll need Map to do mapping, where in JS you can just use simple object.
  • Most extensible (e.g. Operator Overloading)
  • Language is cross platform, API is not
  • You'll need to define types for external codes, but it is not as popular as TypeScript, so good luck with that.
  • I wonder when would people prefer Haxe:
    • Comming from Java, really hates JS?
    • Want to jump to another platform, but don't want to learn new language?
  • The generated JS is the the most complex among these langauges, and performance is not that good as well.

CoffeeScript

  • It is just JavaScript, with lots of syntax suger
  • Not that many new features, most of them are for convenience only, and you have to understand JS anyway
  • Really fast for development
  • The compiled JS is considered easy to read
  • Not that bleeding edge
    • Generator support after 2 years it was proposed
    • Doesn't support named function just because of IE8
  • Future compatibility with ES6 is unclear (for of and for in)

CoffeeScript was a great tool when I first touched it, it makes coding very fast, because you can write common patterns with very few characters. For example a?.b?.c?() instead of checking null for every layer, auto return and non-scoped function => are cool as well. However, I find it not very future-prove, for example generator tooks 2 years to integrate, and we are dragged behind because of IE8 compatibility. They decided they are not going to add new things until all browsers support it, and that can be a trouble if you want to use new functions. If you let me choose today, I will start any all projects with ES6 over CoffeeScript.

LiveScript

  • I like this language the most among the five

  • CoffeeScript's friend, very much alike

  • Haskell inspired prelude-ls, I like it

  • It makes functional programming in JS happier (Piping|>)

  • Back arrow <- fits the callback-based design of Node.js very well.

    • Here is a file with socket.io and sending http request, all of them are async, and the deepest indent level is only 2!
  • They are open to add new things into the langauge (Generator, lots of new operator like >>> and >>>>, build in functions like import)

  • Put pattern into language (e.g. currying, dash-var-name compiles to camelCase)

  • Platform awared design (require! and export keywords for Node.js)

  • Does have quirks, so be careful

      a[1 to 1] = []; // a[1] = [];
      a[x to x] = []; // a.splice(x,1);
    
  • Generated JS is more difficult to read than CoffeeScript

LiveScript is a very cute tool to try out for some pet projects, but if you are really serious about your project in the future, ES6 / TypeScript is the choice.

Blog Logo

b123400


Published