Dart helps developers build fast HTML5 apps for the Web. Currently in Technology Preview (with a Beta release planned for this year), this open source project is building a "batteries included" developer platform that integrates a new language, libraries, an editor, a virtual machine, and a compiler (with JavaScript output).
History and Rationale
Before starting the Dart project, engineers Lars Bak and Kasper Lund were responsible for building V8, the original high-speed JavaScript engine now found in Chrome and used as the underlying technology in node.js. Their experience building high-performance virtual machines (including previous work on Java and Smalltalk VMs) led them to conclude that Web application performance and Web developer productivity could be significantly improved by introducing a new language and runtime for the Web. The result was the Dart project.
The Web is advancing at a tremendous pace: For example, the Chrome browser is updated every six weeks to include the latest HTML5 features. The development cycle for Web programming is highly iterative, with the reload button acting as your compiler. However, it should be easier to build larger, more complex applications. It has taken far too long for productive tools to emerge, and there's still much more work to be done. Even though JavaScript engines are getting faster, Web app startup performance can be drastically improved. In addition, it should be easier to understand the program structure and work with larger teams. For large, complex Web apps, we need more structure and tools.
The Dart project was initiated to address these issues and to fulfill the needs of developers from all platforms, not just dedicated Web developers. The engineers on the Dart project want to make it easier to meet the new user demands of full-featured, beautiful, 60-FPS Web apps.
The Dart Language
The Dart language is designed for mass adoption, so it should be easy to use for a wide range of developers. It is an object-oriented language with classes, single inheritance, lexical scope, top-level functions, and a familiar syntax as shown in the following example.
class Point { num x, y; Point(this.x, this.y); num distanceTo(Point other) { var dx = x - other.x; var dy = y - other.y; return Math.sqrt(dx * dx + dy * dy); } } main() { var p = new Point(2, 3); var q = new Point(3, 4); print('distance from p to q = ${p.distanceTo(q)}'); }
Listing One: A small sample of Dart code.
The code in this listing includes the following:
Line 3: A constructor with handy sugar for the common "this.x = x
" pattern found in constructors.
Line 5: Omit the type annotation, because the editor can infer the local variable's type.
Line 11: Every Dart program starts with main()
.
Line 14: Notice the string interpolation for easy string creation.
While keeping things generally recognizable, Dart also introduces a few features that haven't been seen in a mainstream programming language.
Optional Types
Optional static types are perhaps the most interesting feature of Dart. Instead of the "guilty until proven innocent" experience that you get from mainstream statically typed languages, Dart trusts the developer. Think of Dart's static types as annotations or documentation. Tools such as the editor can use the types to give you early warnings and errors. But you have the option of using var
for dynamically typed variables when types can be inferred or when the developer can't express what they need to with a traditional type annotation. Gilad Bracha has provided more insight into Dart's optional static types.