While the question was "Are the purposes of the languages the same?", the real question is: "How can we make web programming better from where we are?".
Both projects try to do this considering
programming language (TypeScript makes a small but very clean step, Dart makes the more revolutionary move that is still moving)
interoperability with existing js code (0 transition in TypeScript which compiles to js, complicated in Dart, since 2 VMs talk to each other)
software engineering practices (Dart only, web components and shadow dom)
Over the last 3 days I dived deep into Dart and then into TypeScript. My CoffeeScript codebase went to 2000s lines of code, too much to be handled with lovely but too fluffy CoffeeScript. The problems I faced was that CoffeeScript lacks features that languages designed for medium to large scale programming have: interfaces, modules, type safety. But there was one even much more serious issue with coffee and js: The js "this pointer" weirdness affected my sanity and CoffeeScript does not help anything here.
So here my results after 3 days of eval and usage:
Dart
Went thoroughly through the tutorial, reading 1 book, skimming 2nd book and tried the demos. I thought, Dart that is the future. Then I tried to migrate my app to Dart. That was were my enthusiasm went down from 100 to 10. Here is why:
The Dart Editor is the only way to program Dart. While plugins for Sublime Text exist, they do not provide features like intellisense, code completion (correct me if I am wrong). The Dart Editor is however in pre alpha quality. While it does support supercool magic things like updating the web page when you edit the CSS file (! really cool) it hangs or crashes several times a minute. So you type 5 letters and 2 times you have to wait 2 seconds or 15 seconds between typing. And I had a project with some lines of code, so did not want to wait what happens when 1000s lines are in. Moved a file from one folder to the other inside Dart Editor, crash. Debugging with the Dart Editor is at first sight better than all js debugging tools I know (chrome is my choice), but there are still too many things missing: No immediate window (this makes js debugging much better at the moment), no watches.
Politics and Escape Possibilities: Some say that Apple, MS and Firefox will never ever provide Dart VMs. Well, I am not so sure, but at least for Apple this appears at the moment very certain. For the others its more likely than the opposite. So no problem, we can convert Dart to JavaScript. The way this integration works is really great, Dart maintains a js stub that keeps the js code connected to the Dart Editor, so a print()
statement still appears in Dart Editor, cool. But here comes the but: the footprint of such converted code is high. 150kB or so (before minification). I did not dig too much into the exact size, so do not nail me down on this.
Language Maturity. Beside the way too serious issues with Dart Editor popping into my face 3 times a minute I also found it unacceptable that every source about Dart code you find uses a different Dart. The language changes every day. You find a post from 5 weeks ago? It is outdated. You try the samples from the Google tutorial? At least 1 sample does not compile since an API changed. Even mundane things, like attaching an event to a DOM element are in good move.
Integration with existing js libraries is a bit involved. 2 VMs need to communicate here, its tricky.
As a conclusion, you cannot seriously use Dart as of today, and diving into it is not too much fun due to 1 and 3. Both points will disappaer over time. About the 2 point, Google published performance benchmarks some days ago demonstrating that their compiled js is better than handwritten js. My compliments, great job. Loading time might still be behind due to the footprint issue as said. However, if the footprint code gets used by many many sites, it might be available cached and voila, disappears as well.
So: I consider Dart a great project, using it at the moment carries a good portion of unforeseeable risk and it will take this year to get it to good stable level.
TypeScript
Evaluating TypeScript is very easy, takes 1 or 2 hours and you know everything. Reading the language spec document and a short book (TypeScript revealed) revealed, I knew everything and started programming. I was then surprised to find that TypeScript's additions to JavaScript just fill every serious need I had to enhance my client programming. Here the highlights:
Interfaces. Encapsulation and interfaces allow me to structure my code easily. Perfect!
Class State.. TypeScript allows to express the state that instances of a class carry explicitly, or better it enforces it. This is a large step better compared to js or coffee.
this
call craziness mitigated. Inside arrow functions, TypeScript makes the this
pointer like any normally behaving citizen.
Editor, Intellisense. TypeScript comes with 100% top perfect intellisense that reacts in the micro or millisecond range as used from Visual Studio when programming C#. TypeScript headers for all important js libraries exist too. Great great great.
Experience and Risk. Using TypeScript carries zero risk, the language is clearly defined, perfectly stable, it is just js with sugar, nothing unforeseeable.
Actually, these enhancements give me everything I needed. The only thing I would like to see in the future are generic collections. But that is peanuts.
So what about performance? While I consider myself a performance freak, I do not believe that there is any project that would make the technology choice here based on performance. Both are in the js liga.
If you are interested in the future of web programming, both are great efforts, TypeScript is much more pragmatic and usable now, Dart is a very interesting lab project that will be usable once mature editors and debuggers are available and the scope of projects doable with it will depend on politics.
In any case the 3 eval days were mostly fun and I learned a lot, if you find the time, it takes 1 day for Dart and 2 hours for TypeScript to make your own opinion. Try it.
Update October 2014
It has been a while and ex post it appears the assumption that Typescript is the safe stable route to go was quite right. I just found a (very) prominent statement about Typescript, Dart and Closure:
I have been interested in the challenge of Web programming in the large for quite some time. I believe that Google Closure is currently still the best option for large-scale JavaScript/Web development, but that it will ultimately be replaced by something that is less verbose. Although Dart shows considerable promise, I am still dismayed by the size of the JavaScript that it generates. By comparision, if TypeScript can be directly translated to JavaScript that can be compiled using the advanced mode of the Closure Compiler, then we can have all the benefits of optimized JavaScript from Closure without the verbosity. What's more, because TypeScript is a superset of JavaScript, I believe that its syntax extensions have a chance of making it into the ECMAScript standard at some point, whereas the chances of Dart being supported natively in all major browsers is pretty low.
http://blog.bolinfest.com/2013/01/generating-google-closure-javascript.html
Michael Bolin is a long time (ex)google (ex)fb front end hero, also involved in google closure (get his book about Closure).
Google Traceur
Google's appraoch to live ECMA Script 6 today is its Traceur project:
https://github.com/google/traceur-compiler
Compared to Typescript, tooling support is presumably far behind as of today. On the upside however, it is much faster in adopting overly cool future js language ehancements like iterators or comprehensions.
Facebook Flow, Google AtScript
provide similar features as TypeScript.
"One may wonder what’s with these different JavaScript type checking solutions and what to do about it. A good news is that Microsoft, Facebook and Google are collaborating on these, according to Microsoft’s Jonathan Turner:
The TypeScript team is working with both the Flow and AtScript teams to help ensure that resources that have already been created by the JavaScript typing community can be used across these tools. There's a lot these projects can learn from each other, and we're looking forward to working together going forward and creating the best tools we can for the JavaScript community. In the long term, we will also be working to fold the best features of these tools into ECMAScript, the standard behind JavaScript."
infoq article on fb flow