1. Dart
{
Google’s answer to Javascript
Raoul-‐‑Gabriel Urma
2. What is Dart?
Ñ Dart is a new class-‐‑based programming language for
creating structured web applications. Developed with
the goals of simplicity, efficiency, and scalability, the
Dart language combines powerful new language
features with familiar language constructs into a clear,
readable syntax.
Compiles to Javascript
Runs on VM
3. Design goals
Ñ Create a structured yet flexible programming
language for the web.
Ñ Make Dart feel familiar and natural to programmers
and thus easy to learn.
Ñ Ensure that all Dart language constructs allow high
performance and fast application startup.
Ñ Make Dart appropriate for the full range of devices
on the web—including phones, tablets, laptops, and
servers.
Ñ Provide tools that make Dart run fast across all
major modern browsers.
4. In a nutshell…
Ñ Class-‐‑based
Ñ Single inheritance
Ñ Pure (everything is an object)
Ñ Optional types
Ñ First-‐‑class functions
Ñ Java-‐‑like syntax (shorter)
Ñ Null!!
Ñ Actor model (isolates light vs heavy)
Ñ Collections classes (Set, Map, List, Queue)
Ñ Named constructors
“The type system is unsound, due to the covariance of generic types.
This is a deliberate choice (and undoubtedly controversial).
Experience has shown that sound type rules for generics
fly in the face of programmer intuition. It is easy for tools to provide
a sound type analysis if they choose, which may be useful for tasks
like refactoring.”
5. Fun with Dart
Ñ h]p://try.dartlang.org/s/F-‐‑MX
Ñ Variables initialized to null
Ñ Generics are covariant
6. Ñ main() {
Ñ List<Banana> listOfBananas = new List<Banana>();
Ñ List<Fruit> listOfFruits = listOfBananas;
Ñ listOfFruits.add(new Apple());
Ñ print(listOfBananas[0]); // apple
Ñ }
Ñ class Apple extends Fruit{
Ñ toString() { return "ʺapple"ʺ;}
Ñ }
Ñ class Banana extends Fruit{
Ñ toString() { return "ʺbanana"ʺ;}
Ñ }
Ñ class Fruit{
Ñ toString() { return "ʺfruit"ʺ;}
Ñ }
8. Dart vs Newspeak [1]
Ñ Class-‐‑based ✓
Ñ First-‐‑class modules ✗
Ñ Reflection (coming soon -‐‑ based on mirrors [2]) ✓
Ñ Mixins ✗
Ñ Names as method invocation ✗
Ñ Immutability enforcement ✗
[1]: h]p://bracha.org/newspeak-‐‑modules.pdf
[2]: h]p://bracha.org/mirrors.pdf
9. Dart vs CoffeeScript
Ñ Pa]ern matching ✗ (coming soon? [1])
Ñ Prototype Based ✗
Ñ List comprehension ✗
Ñ Compiles to JS ✓
[1] Pa]ern Matching for an Object-‐‑Oriented and
Dynamically Typed Programming Language – Gilad Bracha