Dart: Google's Early Vision for a Structured Web
It’s October 2011, and the web development world is in a bit of a shock. Google has officially released Dart, a new "batteries-included" language designed to solve the fundamental problems of JavaScript: performance, structure, and scalability.
While we're all trying to use Object.create and prototypes, Dart gives us a familiar, class-based language that looks like a blend of Java and JavaScript.
Optional Typing
One of Dart’s most interesting features is optional types. You can write quick scripts without types, or add them for better tooling and documentation as your project grows.
// Dart 2011 syntax
class Hello {
String name;
Hello(this.name);
void sayHi() {
print("Hello, ${name}!");
}
}
void main() {
var h = new Hello("World");
h.sayHi();
}
The Dart VM and "Dartium"
Google’s vision isn't just a transpiler (though they have dart2js). They want to ship a Dart VM directly in Chrome. They've even released "Dartium," a special build of Chromium that runs Dart natively. The speed difference is supposedly massive.
Libraries and Tools
Unlike JS, which has a fragmented ecosystem, Dart comes with a robust standard library for everything from collections to HTML manipulation.
import 'dart:html';
void main() {
Element element = query("#my-button");
element.on.click.add((event) {
element.text = "Clicked!";
});
}
Is 2011 the year JavaScript starts its decline? Only time will tell if the world is ready to switch to Google’s vision of a structured web.