Turn up your nose at Dart and smell the CoffeeScript

You think JavaScript has gone stale? Then consider CoffeeScript.

For coders on the bleeding edge of web development, Dart and CoffeeScript both merit consideration. InfoWorld's Martin Heller explains why, for him, CoffeeScript has the lead.

My first reaction whenever I hear about a new programming language is twofold:

  • Oh boy, another programming language! Something new to learn! How exciting!
  • Oh crap, another programming language. Something new to learn. Life is too short.

It's how I reacted to Fortran, PL/I, Snobol, Lisp, Pascal, C, Basic, Modula2, C++, Visual Basic, Java, JavaScript, Perl, Python, C#, Visual Basic .Net, J++, Google Go, and now Google Dart. Obviously, some of those languages are still in active use, but many have been relegated to the dustbin of history.

For several years, I fed reaction No. 1 by writing the monthly "Mr. Computer Language Person" column for Byte.com. But these days, reaction No. 2 tends to dominate, as I'm deeply involved in getting a product out the door (at Alpha Software) and don't have much free time.

A better JavaScript alternative is CoffeeScript

If your goal is to replace the verbose grammar of JavaScript with something more concise and elegant without adding any overhead or keeping you from using jQuery or any other JavaScript framework, you might want to look at the CoffeeScript project. Influenced by Python, Ruby, Haskell, and YAML, CoffeeScript compiles one-to-one into the equivalent JavaScript; does away with unnecessary semicolons, braces, and declarations; and adds functional programming ideas like array comprehension and pattern matching.

CoffeeScript came out of the Ruby community, and it is included in Ruby on Rails 3.1. Like everything to do with Rails, CoffeeScript has been hyped -- perhaps overhyped.

But if you're looking for an alternative to the old, verbose, but tried and true JavaScript, the new, elegant, CoffeeScript is worth a look.

The case for Dart rests on JavaScript staying static

If functional programming isn't your style, but object-oriented programming is, consider Google Dart. Right now, unfortunately, Dart looks interesting, but it is useless unless you want to configure a Linux VM to build the tools from source code. In the long term, whether Dart becomes useful depends largely on whether it becomes a widely supported standard before the deficiencies of JavaScript are remedied.

Why is it interesting? The primary reason for Dart being interesting is that it remedies some of the deficiencies of JavaScript. Dart is a virtual-machine-based scripting language with optional type checking and both classes and interfaces, which are structured/object-oriented programming constructs familiar to most programmers. Dart also has the option to compile Dart code into JavaScript. To an experienced developer, Dart looks a lot like C# syntax, with some features reminiscent of Python. Dart also has an Erlang-like construction called "isolates" that implement shared-nothing concurrent processes that communicate over ports.

JavaScript, on the other hand, is a dynamic virtual-machine-based scripting language with weak type checking, and instead of classes, it has objects with an unusual inheritance mechanism called "prototypes." JavaScript also lacks any kind of module mechanism, so name collisions become a common issue when you try to combine JavaScript libraries.

On the gripping claw, there are a lot of smart people working on it, JavaScript is an ECMA standard, it's baked into every Web browser that matters, and as a language, it's not standing still. The JavaScript Harmony or ES.next project will eventually fix what actually ails JavaScript, if you believe JavaScript proponents. Google research scientist Mark S. Miller disagrees and says that "JavaScript has been a part of the Web platform since its infancy, but the Web has begun to outgrow it."

Should you care about Dart? I wouldn't worry about it right now, unless you work for Google. But if and when you start seeing it implemented in browsers other than Chrome, and if and when it has demonstrated some speed or productivity advantages, it might be worth some attention.

Copyright © 2011 IDG Communications, Inc.