I don’t think there are many people out there that would argue that JavaScript isn’t an important language. It certainly is, and with the recent death of Flash and Silverlight in the browser and the hype behind HTML5, to say nothing of Node, it is actually getting more popular

I also don’t think there are many people out there that would argue that JavaScript is a heavily broken language too. As systems written in JavaScript become larger and more complex, the language flaws become more and more pronounced. Just as C++ ultimately came about from C’s (arguable by some) inability to deal with complexity, a number of companies and groups are looking at possible successors to JavaScript. Generally all of these languages are backward compatible with JavaScript in some form. Let’s take a look at the contenders for the short term future of JavaScript.

ECMAScript 6 AKA Harmony AKA ES.next

When talking about the future of JavaScript, the most logical place to start is … well, the future of JavaScript, the next version. The spec is a work in progress and you can read it here, the most recent revision as of writing (September 27th, 2012). It would seem obvious that the next version of JavaScript would be ECMAScript 6, but don’t bet the farm just yet. After all, ECMAScript 6 is effectively a scaled back version of ECMAScript 4, while ECMAScript 5 (the JavaScript version in common usage today), is essentially a fork of ECMAScript 3. Firefox and Chrome already support bits of ECMAScript 6, so it’s future is quite bright, but by no means are things certain. Plus there is no way of knowing how long until ECMAScript 6 is supported enough to actually make it useful. For an idea of where ECMAScript support in various browsers is, check out this handy table.

This has opened the door to a number of alternatives, many are languages that compile down to JavaScript making them useful today. Others (like Dart) compile down to JavaScript as a fallback, but perform better in their native environment.

The 900lb gorillas.

Two of the companies are very interested in the future of JavaScript are Google and Microsoft. Each has created a language they hope will be the future of JavaScript, Dart and TypeScript respectively.

This interview between Anders Hejlsberg ( Microsoft, creator of Delphi, C# and now TypeScript ) and Lars Bak ( Google, creator of V8 JavaScript engine and Dart ) is very good summary. It allows each developer to describe their opinions of the existing problems with JavaScript ( on which they largely agree ) and describe the strengths of each of their companies offerings.

Anders Heljsberg & Lars Bak on TypeScript/Dart and the problems with JavaScript today

Google Dart

http://code.google.com/p/dart/ or http://www.dartlang.org/

In Their Words:

Why Dart?

At Google we’ve written our share of web apps, and we’ve tried in many ways to make improvements to that development process, short of introducing a new language. Now we think it’s time to take that leap. We designed Dart to be easy to write development tools for, well-suited to modern app development, and capable of high-performance implementations.

Dynamic or Static Typed?

Dynamic

Key language features

Compiles down to JavaScript, or to the Dart VM ( which is currently only available in Chrome ). Code running in the Dart VM will perform better.

Language is basically JavaScript with prototypes removed and classes added. They’ve added lexical closures, sane this management, optional static types, named parameters, cleaner event and DOM programming and more.

The language also comes with an IDE, the Dart Editor, which is a mash-up of Eclipse, Chromium and the DartVM. For those like me that prefer WebStorm/IntelliJ over Eclipse, they also have a plugin available. There used to be a cloud based editor, but it appears to have been retired.

My 2 cents

Dart technically solves most of the problems with JavaScript and is compatible with existing JavaScript. That said, I checked out Dart shortly after it was released, then again 6 months later and as usual, Google’s developer support stunk. They just don’t put the extra effort in to making the experience easy on developers ( at the time, the Windows build didn’t work, you need to compile everything yourself, etc… this lack of polish is just as common with other Google developer tools such as GWT, NativeClient even Android), but the package seems to be improved quite a bit. Just a warning though, if you aren’t experienced with Google developer support, be prepared for a ton of frustrations if you run in to any problems.

Probably the biggest flaw with Dart is going to be the lack of adoption. Dart compiles to JavaScript as a fall back, but the VM is obviously the preferred platform. Google announced their intention of submitting Dart to a standards body, but do you see Microsoft or Mozilla adopting Dart? Yeah, me neither. That said, Chrome is getting a pretty big install base.

My biggest problems are the above mentioned Google support, and their tendency to kill off projects at the drop of a hat lately.

Microsoft TypeScript

http://www.typescriptlang.org/

In Their Words:

Why TypeScript?

TypeScript is a language for application-scale JavaScript development. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source.

Dynamic or Static Typed?

Static

Key language features

TypeScript is compiled down to JavaScript.

Language allows you to add static types to JavaScript, allowing you to catch type errors during the compilation process ( although the compilation will still generate a JS file ). Allows you to mix and match TypeScript and JavaScript in existing files. Adds new constructs to the language such as classes, interfaces and modules.

IDE support is available in the form of a Visual Studio 2012 plugin, as well as plugins for Sublime Text, Vi and Emacs. They also have Node support out of the box and you can download TypeScript using NPM.

My 2 cents

I will admit, I am a bit of a Anders fanboy, so that has gotten me excited about this language. Language design is all about pragmatic choices, and Anders just seems to pick the right compromises.

At the end of the day, TypeScript is less of a gamble than Dart, and this has it’s advantages and disadvantages. As Lars said in that video above, TypeScript is “the safe bet” and that is a pretty apt description. It is a layer on top of JavaScript and nothing more, in many ways it is quite similar to CoffeeScript. In the end though, TypeScript is probably the one that will best integrate with existing Javascript and given the massive variety of existing code, that is probably a pretty big advantage. At the end of the day though, TypeScript is ends up being JavaScript, so don’t expect any performance improvements.

The tooling support is shockingly not Microsoft. Would you have ever expected Vi and Emacs support from day 1? What about Node support? There is a noted lack of documentation at this point, which is shocking for a Microsoft product. They do however have a nifty Playground/Tutorial environment that allows you to type TypeScript and see the generated JavaScript. Sadly for now, comments and whitespaces are mangled as part of the process, although this is a temporary flaw.

CoffeeScript

http://coffeescript.org/

In Their Words:

CoffeeScript is a little language that compiles into JavaScript. Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

The golden rule of CoffeeScript is: "It’s just JavaScript". The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime

Dynamic or Static Typed?

Dynamic

Key Language Features

Coffeescript is a whitespace ( as opposed to curly brace ) based language that compiles down to JavaScript. It is certainly the elder statements of the group and has been around for a number of years.

Coffeescript provides a number of features to JavaScript including a class system, lexical scoping, splats (…) for variable arguments, array slicing and more. Additionally it provides a layer of syntactical sugar over some of the JavaScript warts such as is instead of === or unless as the inverse of if.

Coffeescript also offers impressive tooling support. Like TypeScript, it is available as a Node utility, making installation via NPM trivial. Most IDEs support Coffeescript ( IntelliJ, Eclipse, WebStorm, Netbeans, Sublime Text, etc ) out of the box.

My 2 cents

I only gave CoffeeScript the smallest of evaluations and that was a few years back. You see, I have an irrational hatred of whitespace based languages. What I found most irksome ( and TypeScript fixed this ), is that it’s a language on-top of JavaScript, not within Javascript. So you had to program things the Coffeescript way, then compile it to JavaScript. Coffeescript felt like a completely different language than JavaScript, while neither Dart nor TypeScript gave me that impression. Mostly though, I never got over my hatred of whitespace based languages.

All that said, CoffeeScript solved many of the problems that Dart and TypeScript are setting out to solve, and it solved them years ago. It’s by far the most mature and as a result had the most time to iron out the kinks.

Other Options

Dart, TypeScript and CoffeeScript are by no means the only options when it comes to more programmer friendly JavaScript programming languages, but they are the three that are closest to JavaScript itself. The following are a selection of other languages that will compile to JavaScript.

GWT – Google Web Toolkit

https://developers.google.com/web-toolkit/

Google Web Toolkit (GWT) is a development toolkit for building and optimizing complex browser-based applications. GWT is used by many products at Google, including Google AdWords and Orkut. It’s open source, completely free, and used by thousands of developers around the world.

Basically GTW is a Java –> JavaScript compiler. That is over generalizing, but basically you write your code using a subset of libraries in the Java language, and it is compiled down to JavaScript. Or a bit of mix and match, with Java running on the server and JavaScript on the client. The programmer never really works in JavaScript when working with GWT.

As is pretty typical with Google projects, IDE support is mostly Eclipse based. There are a few published books available for GWT. GWT has been around for quite a while and integrates nicely with Google App Engine. That said, if you aren’t a Java developer, GWT really isn’t for you.

Haxe

http://haxe.org/

Haxe is a powerful modern language with many compelling features. It is aimed at giving developers a tool to create websites & applications using a single unified programming language. Whether you use Haxe for its cross-platform features, or focus on a single platform, there are many reasons to adopt it.

Haxe is a language that allows you to compile down to JavaScript, Flash, NekoVM, PHP, C++, C# and Java. It provides a standard language and library that compiles down to the mentioned languages, while filling in the missing pieces of each language, such as packages and typing for JavaScript, reflection for C++, etc. The Haxe language itself is derived from ActionScript 3, which itself is a ECMAScript language. Haxe has pretty good IDE support. Haxe also has a few published books which is always handy.

I’ve not yet used Haxe, mostly because I have no prior ActionScript experience and because I never really had the time to look into it further. That said, HaxeNME, which is a gaming library targeting web, mobile and desktop certainly has piqued my interests.

Other other options…

This doesn’t even come close to listing all of the languages that compile to JavaScript, for a more complete list see this. This does however cover the major players, at least as I see them. If you think I made a major omission or mistake in this list, please let me know!

JavaScript is becoming more important and JavaScript programs are becoming more complex. The language does have a number of flaws, but fortunately there are a number of options to help you cope, at least until ECMAScript 6 arrives.

General Programming