You will need the Dart SDK, which is freely available from dartlang.org. Most of the book works with Dartium, a preview release of Chrome that is included in the SDK and has the Dart VM built-in. Some of the examples use either the dart2js tool or the Dart Editor to compile Dart down into JavaScript—both are part of the SDK.
5 Things You Don’t Know About Dart
5. It has brilliant server and browser package management. The “Pub” package manager works the same whether you are writing server code or a web application. List your dependencies in a pubspec.yaml file, run “pub get”, and your dependencies (and their dependencies) are immediately available. Whether it is compiled to JavaScript or run natively in the browser, Dart’s libraries and packages make organizing code a breeze.
4. It’s not really statically typed. You can declare variables with or without types—it makes no difference whatsoever at runtime. If you like declaring variables with var, go right ahead. If you like documenting code with types, feel free (it’ll help with docs and code analysis tools).
3. It has beautiful unit (and acceptance) testing built into the language from the outset. To build bulletproof applications, you need a strong testing suite. And Dart has you covered. Brilliantly.
2. Dart does not compile directly to JavaScript. To support all modern browsers (even IE10+), dart2js compiles to a JavaScript compatibility layer. That JavaScript compatibility layer is quite large, so dart2js performs sophisticated tree shaking so that it can drop unused bits, keeping the compiled code and compatibility layer as small as possible. The Dart team works hard to ensure that this compatibility layer works across the modern web so you don’t have to. No more browser checking. No more weird browser-specific bugs. Your code just works. Everywhere.
1. It rivals Ruby for code beauty. In addition to its simple, classical inheritance, Dart is loaded with syntactic sugar to make a programmer’s life easier. To name just a few, Dart has:
- Method cascades (calling multiple methods on the same object).
- First-class support for optional parameters (no more parsing an options hash, yay!)
- Getter and setter methods (methods that look like properties, but are backed by a normal method).
- Assignment of instance variables in the constructor declaration instead of the body.
- String interpolation—no more chains of plus signs!
It’s the little things really. And Dart has so many little things that add up to greatness.
0. (BONUS!) It is fast. In many cases, the compiled JavaScript is faster than the JavaScript that you can hand-code. Don’t believe me? Check out the benchmarks and try it yourself!