Dart (programming language)

From Wikipedia, the free encyclopedia
  (Redirected from Google Dart)
Jump to: navigation, search
Dart (programming language)
Dart logo wordmark.png
Paradigm Object-oriented and Class-based
Designed by Lars Bak and Kasper Lund
Developer Google
Appeared in November 14, 2013; 15 months ago (2013-11-14)[1]
1.8.5[2] / January 21, 2015; 41 days ago (2015-01-21)
License BSD license
Website www.dartlang.org

Dart is an open-source Web programming language developed by Google. It was unveiled at the GOTO conference in Aarhus, October 10–12, 2011.[4] The goal of Dart is "ultimately to replace JavaScript as the lingua franca of web development on the open web platform".[5] Until then, in order to run in mainstream browsers, Dart relies on a source-to-source compiler to JavaScript. To attempt performance gains, Google engineers have evolved Dart as well as extended JavaScript, since "pursuing either strategy in isolation [would be] likely to fail."[5] However, Dart has had mixed reception and the Dart initiative has been criticized by industry leaders for fragmenting the web, in much the same way as VBScript. According to the project site, Dart was "designed to be easy to write development tools for, well-suited to modern app development, and capable of high-performance implementations."[6]

Dart is a class-based, single inheritance, object-oriented language with C-style syntax. It supports interfaces, abstract classes, reified generics, and optional typing. Static type annotations do not affect the runtime semantics of the code. Instead, the type annotations can provide documentation for tools like static checkers and dynamic run time checks.


The project was founded by Lars Bak and Kasper Lund.[7]

In August 2014, Seth Ladd became the Product Manager for Dart at Google, moving up from a Developer Advocate.


There are three primary ways to run Dart code:

Compiled as JavaScript
When running Dart code in a web browser, the primary intended mechanism is to pre-compile the Dart code into JavaScript using the dart2js compiler. Compiled as JavaScript, Dart code is compatible with all major browsers with no specific browser adoption of Dart being required. Through optimization of the compiled JavaScript output to avoid expensive checks and operations, code written in Dart can, in some cases, run faster than equivalent code hand-written using JavaScript idioms.[8]
In the Dartium Browser
The Dart SDK ships with a version of the Chromium web browser modified to include a Dart virtual machine (VM). This browser can run Dart code directly without compilation to JavaScript. It is intended as a development tool for Dart applications, rather than as a general purpose web browser.[9] When embedding Dart code into web apps, the current recommended procedure is to load a bootstrap JavaScript file, "dart.js", which will detect the presence or absence of the Dart VM and load the corresponding Dart or compiled JavaScript code, respectively,[10] therefore guaranteeing browser compatibility with or without the custom Dart VM.
The Dart SDK also ships with a stand-alone Dart VM, allowing dart code to run in a command-line environment. As the language tools included in the Dart SDK are written primarily in Dart, the stand-alone Dart VM is a critical part of the SDK. These tools include not only the dart2js compiler, but also a package management suite called pub. Dart ships with a complete standard library allowing users to write fully functional system apps, such as custom web servers.[11]

Runtime modes[edit]

Dart programs run in one of two modes. In "checked mode", which is not the default mode and must be turned on, dynamic type assertions are enabled. These type assertions can turn on if static types are provided in the code, and can catch some errors when types do not match. For example, if a method is annotated to return a String, but instead returns an integer, the dynamic type assertion will catch this and throw an exception. Running in "checked mode" is recommended for development and testing.

Dart programs run by default in "production mode", which runs with all dynamic type assertions turned off. This is the default mode because it is the fastest way to run a Dart program.

Compiling to JavaScript[edit]

dart2js is the current Dart-to-JavaScript compiler from Google, as of March 2009, and is written in Dart. dart2js is intended to implement the full Dart language specification and semantics. It is an evolution of earlier compilers: dartc was the first compiler to generate JavaScript from Dart code but has since been deprecated. Frog was the second Dart-to-JavaScript compiler and was written in Dart. Frog never implemented the full semantics of the language, leading to the development of the dart2js compiler.

On March 28, 2013, the Dart team posted an update on their blog[12] addressing Dart code compiled to JavaScript with the dart2js compiler, stating that it now runs faster than handwritten JavaScript on Chrome's V8 JavaScript engine for the DeltaBlue benchmark.[13]


On November 18, 2011, Google released Dart Editor, an open-source Dart editor based on Eclipse components, for Mac OS X, Windows, and Linux-based operating systems.[14] The editor supports syntax highlighting, code completion, JavaScript compilation, running both web and server Dart applications, and debugging.

On August 13, 2012, Google announced the release of an Eclipse plugin for doing Dart development.[15]

JetBrains IDEs also support the Dart language. Dart plugin[16] is available for IntelliJ IDEA, PhpStorm and WebStorm. This plugin supports many features such as syntax highlighting, code completion, refactoring, debugging, and more.

Chrome Dev Editor[edit]

It has been known since November 2013[17] that the Chromium team is working on an open source, Chrome App-based development environment with a reusable library of GUI widgets, codenamed Spark, later renamed as Chrome Dev Editor.[18] It is built in Dart, and contains a GUI widgets library powered by Polymer.[19] Developer preview version is available in Chrome Web Store.

SIMD on the Web[edit]

In 2013, John McCutchan announced[20] that he had created a performant interface to SIMD instruction sets for the Dart programming language, bringing the benefits of SIMD to web programs for the first time, for users running Google's experimental Dartium browser. The interface consists of two types:

  • Float32x4, 4 single precision floating point values.
  • Uint32x4, 4 32-bit unsigned integer values.

Instances of these types are immutable and in optimized code are mapped directly to SIMD registers. Operations expressed in Dart typically are compiled into a single instruction with no overhead. This is similar to C and C++ intrinsics. Benchmarks for 4×4 matrix multiplication, 3D vertex transformation, and Mandelbrot set visualization show near 400% speedup compared to scalar code written in Dart.

Browser adoption[edit]

A special version of Chromium (the open-source browser at the core of Google Chrome) comes with the Dart virtual machine, allowing it to run Dart programs.[21] As of February 2015, Microsoft Internet Explorer, Mozilla Firefox, Opera Software's Opera browser, and Apple Safari have no plan to embed a separate Dart VM.[citation needed]

Dart source code can be compiled to JavaScript, allowing applications written in Dart to run in all modern web browsers. In the M1 version, released in October 2012, the generated JavaScript reached about 78% of the performance of hand-written JavaScript while native Dart code ran about 21% faster than similar code in V8.[8]


A Hello World example:

void main() {
  print('Hello World!');

A function to calculate the nth Fibonacci number:

int fib(int n) => (n > 1) ? (fib(n - 1) + fib(n - 2)) : 1;
void main() {
  print('fib(20) = ${fib(20)}');

A simple class:

// Import the math library to get access to the sqrt function.
import 'dart:math' as math;
// Create a class for Point.
class Point {
  // Final variables cannot be changed once they are assigned.
  // Create two instance variables.
  final num x, y;
  // A constructor, with syntactic sugar for setting instance variables.
  Point(this.x, this.y);
  // A named constructor with an initializer list.
      : x = 0,
        y = 0;
  // A method.
  num distanceTo(Point other) {
    var dx = x - other.x;
    var dy = y - other.y;
    return math.sqrt(dx * dx + dy * dy);
  // Example of Operator Overloading
  Point operator +(Point other) => new Point(x + other.x, y + other.y);
// All Dart programs start with main().
void main() {
  // Instantiate point objects.
  var p1 = new Point(10, 10);
  var p2 = new Point.origin();
  var distance = p1.distanceTo(p2);

Influences from other languages[edit]

Dart's syntax is typical of the ALGOL language family,[22] alongside C, Java, C#, JavaScript, and others.

The method cascade syntax, which provides a syntactic shortcut for invoking several methods one after another on the same object, is adopted from Smalltalk.

Dart's mixins were influenced by Strongtalk[citation needed][23] and Ruby.

Dart makes use of so-called Isolates as a concurrency and security unit when structuring applications.[24] The Isolate concept builds upon the Actor model, which is most famously implemented in Erlang.

The Mirror API for performing controlled and secure reflection was first proposed in a paper[25] by Gilad Bracha and David Ungar and originally implemented in Self.


Dart has been criticized by industry voices outside Google.

Microsoft's JavaScript team has stated that: "Some examples, like Dart, portend that JavaScript has fundamental flaws and to support these scenarios requires a 'clean break' from JavaScript in both syntax and runtime. We disagree with this point of view."[26] Microsoft later released a JavaScript superset language, TypeScript.[27]

Apple engineer Oliver Hunt, working on the WebKit project (which, at the time, powered both Safari and Google's own Chrome browser) stated:

Adding an additional web facing language (that isn't standardized) doesn't seem beneficial to the project, if anything it seems harmful (cf. VBScript in IE).[28]

[...] Adding direct and exposed support for a non-standard language [Dart] is hostile to the open web—by skipping any form [of] 'consensus' driven language development that might happen, and foisting whatever language we want on the Web instead. This implicitly puts any browser that supports additional proprietary extensions in the same position as a browser supporting something like VBScript, and has the same effect: breaking the open web by making content that only works effectively in a single product.[29]

ECMA has formed technical committee TC52[30] to work on standardization of Dart, and, inasmuch as Dart can be compiled to standard JavaScript, it works effectively in any modern browser. ECMA approved the first edition of Dart language specification at its 107th General Assembly on July 2014[31]

Mozilla's previous CEO Brendan Eich, who developed the JavaScript language, stated:[32]

I guarantee you that Apple and Microsoft (and Opera and Mozilla, but the first two are enough) will never embed the Dart VM.

So 'Works best in Chrome' and even 'Works only in Chrome' are new norms promulgated intentionally by Google. We see more of this fragmentation every day. As a user of Chrome and Firefox (and Safari), I find it painful to experience, never mind the political bad taste.

Douglas Crockford, senior JavaScript architect at PayPal, expressed criticism directed at Dart's language design:

It doesn't capture the goodness of JavaScript. It feels like it's trying to go back and be more Java-like. And it's syntax stinks – I don't get it. There's something wrong over at Google.[33]

See also[edit]


  1. ^ Ladd, Seth. "Dart 1.0: A stable SDK for structured web apps". Dart News & Updates. Google. Retrieved 15 November 2014. 
  2. ^ Moore, Kevin. "Dart 1.8.5 Release Notes". Dart Announcements Forum. Google. Retrieved 22 January 2015. 
  3. ^ "Web Languages and VMs: Fast Code is Always in Fashion. (V8, Dart) - Google I/O 2013". Google. Retrieved 22 December 2013. 
  4. ^ "Dart, a new programming language for structured web programming", GOTO conference (presentation) (opening keynote), Århus conference, 2011-10-10 
  5. ^ a b Miller, Mark S (November 16, 2010). ""Future of Javascript" doc from our internal "JavaScript Summit" last week". javascript-standard@google.com (Mailing list). Retrieved 2012-01-22.  Leaked internal Google email.
  6. ^ "Why?", Dart lang (FAQ), We designed Dart to be easy to write development tools for, well-suited to modern app development, and capable of high-performance implementations. 
  7. ^ Ladd, Seth. "What is Dart". What is Dart?. O'REILLY. Retrieved August 16, 2014. 
  8. ^ a b "JavaScript as a compilation target : Making it fast" (PDF). Dartlang.org. Retrieved 2013-08-18. 
  9. ^ "Dartium". Dartlang.org. Retrieved 2013-07-21. 
  10. ^ "Embedding Dart in HTML". Dartlang.org. Retrieved 2013-07-21. 
  11. ^ "An Introduction to the dart:io Library". Dartlang.org. Retrieved 2013-07-21. 
  12. ^ Ladd, Seth (2013-03-28). "Dart News & Updates: Why dart2js produces faster JavaScript code from Dart". News.dartlang.org. Retrieved 2013-07-21. 
  13. ^ "Dart Performance". Dartlang.org. Retrieved 2013-07-21. 
  14. ^ "Google Releases Dart Editor for Windows, Mac OS X, and Linux". 
  15. ^ "Google Release Dart Eclipse Plugin". 
  16. ^ "JetBrains Plugin Repository : Dart". Plugins.intellij.net. Retrieved 2013-07-21. 
  17. ^ Beaufort, François. "The chromium team is currently actively working". 
  18. ^ – A Chrome app based development environment "GitHub: Spark". 
  19. ^ "Chrome Story: Spark, A Chrome App from Google is an IDE for Your Chromebook". 
  20. ^ "Bringing SIMD to the web via Dart". 
  21. ^ "Dartlang.org". Retrieved 2013-07-21. 
  22. ^ http://c2.com/cgi/wiki?AlgolFamily
  23. ^ Bracha, Gilad; Griswold, David (September 1996). "Extending the Smalltalk Language with Mixins". OOPSLA Workshop (OOPSLA). 
  24. ^ http://www.infoq.com/articles/google-dart/
  25. ^ Bracha, Gilad; Ungar, David (2004). "Mirrors: design principles for meta-level facilities of object-oriented programming languages". ACM SIGPLAN Notices (ACM) 39 (10): 331–344. doi:10.1145/1035292.1029004. Retrieved 15 February 2014. 
  26. ^ Niyogi, Shanku; Silver, Amanda; Montgomery, John; Hoban, Luke; Lucco, Steve (November 22, 2011). "Evolving ECMAScript". IEBlog. Microsoft. Retrieved 2012-01-22. 
  27. ^ "Microsoft TypeScript – the JavaScript we need". Ars tecnica. December 22, 2012. Retrieved 2012-10-22. 
  28. ^ Hunt, Oliver (5 December 2011). "WebKit branch to support multiple VMs (e.g., Dart)". webkit-dev (Mailing list). Retrieved 2012-01-22. 
  29. ^ Hunt, Oliver (5 December 2011). "WebKit branch to support multiple VMs (e.g., Dart)". webkit-dev (Mailing list). Retrieved 2012-01-22. 
  30. ^ "TC52 - Dart". Retrieved 2013-12-16. 
  31. ^ http://news.dartlang.org/2014/07/ecma-approves-1st-edition-of-dart.html
  32. ^ Eich, Brendan (2011-09-10). ""Even Brendan Eich admitted...". As if I would not expect, nay demand, that Gila...". Hacker News. Y Combinator. Retrieved 2012-01-22. 
  33. ^ "Crockford on JavaScript - Section 8: Programming Style & Your Brain" (Video). YouTube. YUI Library. 12 November 2011. Retrieved 16 February 2015. 


External links[edit]