Software often requires two or three iterations before you get it right. In our case this led to starting a rewrite of our hybrid mobile application. It had been developed over several years by a diverse group of people with varying coding practices, and it was deemed easier to rewrite it than to refactor it into a maintainable state.
Below is the results of our comparison between the three. This is not an extensive functional evaluation (a luxury not available for startups), but instead based primarily on reading the following books:
- The Little Book on CoffeeScript, by Alex MacCaw
- TypeScript Revealed, by Dan Maharry
- Dart: Up and Running, by Kathy Walrath & Seth Ladd
I can recommend these as good introductions to each language, as each one can be read in a few hours. You may also be interested in Anton Ivanov’s blog post comparing the three with code examples.
CoffeeScript – a fresh coat of paint
$(document).ready -> $.get '/', (data) -> $('body').append "Successfully got the page."
The language has many other influences from scripting languages like Python, Perl and Ruby, such as post-conditionals, operator aliases and string interpolation to name a few. It heavily promotes brevity of code, with the risk of it becoming cryptic to non-experts.
The primary new language features provided are (optional) static typing and a class framework. The type system allows catching a wide variety of problems during compile time, instead of runtime. The class and module framework allows easier modularization and writing of complex applications.
Microsoft has also developed comprehensive IDE support for TypeScript for Visual Studio. The static typing allows it to perform many advanced refactoring operations, such as global renaming, reference searching and code completion, enough to make any scripting language developer envious.
Dart – a fresh look at the web
The Dart language is not specifically designed for a browser, but more as a general usage language. Browser-specific functions, such as DOM manipulation, don’t rely on magic global variables, but are provided as libraries. The language resembles Java in many ways, and most programmers should be comfortable with it in a a day or two.
Which one to choose?
So, which one is the best? As always, that depends.
If we were using Microsoft tools for development, TypeScript would be a very tempting choice. As it is, we’re doing the majority of our development on Linux and Macs using Eclipse. A major part of the benefit of TypeScript comes from the tooling within Visual Studio. As support is developed for more IDEs this may change – for example WebStorm 6 from JetBrain already includes TypeScript support.
If I was starting a new desktop web app, I would definitely consider Dart. It’s a very clean, modern language with extensive libraries out-of-the-box. However, our application must also run on rather old mobile browsers, and interface properly with our native code. If we later find out that Dart code doesn’t run properly or fast enough on some devices, we may be at a dead end. This is a risk we didn’t want to take.
An added benefit is that CoffeeScript is probably the most widely adopted altJS language, and there’s a considerable amount of manuals and explanations for it, and more developers in the community to answer questions. Without any clear numbers, Google Trends provides some idea on the relative interest in each language.
Which language have you chosen for your projects?