Dart (programming language)
![]() |
|
Paradigm(s) | object-oriented |
---|---|
Appeared in | 2011 |
Developer | |
Preview release | 0.11[1] (September 17, 2012 ) |
Typing discipline | optional |
Influenced by | JavaScript, Java |
License | BSD License |
Usual filename extensions | .dart |
Website | www.dartlang.org |
Dart (originally, Dash)[2] is an open source Web programming language developed by Google. It was unveiled at the GOTO conference in Aarhus, 2011 October 10-12.[3] The goal of Dart is "ultimately to replace JavaScript as the lingua franca of web development on the open web platform."[2] Dart is intended to solve JavaScript's problems (which, according to a leaked memo, cannot be solved by evolving the language) while offering better performance, the ability "to be more easily tooled for large-scale projects" and better security features.[2] Google is also working on Dart to help it build more complex, full-featured client-side Web apps.[4]
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.
Contents |
Runtime modes
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 currently is the fastest way to run a Dart program.
Compiler to JavaScript
dartc was the first compiler that emitted JavaScript from Dart code. dartc has been deprecated. Frog was the second instance of a Dart-to-JavaScript compiler, this time written in Dart. Frog never implemented the full semantics of the language, though, and a new compiler called dart2js was created. Also written in Dart, dart2js is the current Dart-to-JavaScript compiler and is intended to implement the full Dart language spec and semantics.
Editors
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.[5] The editor supports syntax highlighting, code completion, JavaScript compilation, running both web and server Dart apps, and debugging.
JetBrains IDEs also support Dart language. Dart plugin[6] is available for IntelliJ IDEA, PhpStorm and WebStorm. This plugin supports many features such as syntax highlighting, code completion, refactoring, debugging, and more.
Deployment targets
Dart is designed to run in modern web browsers, either directly inside a Dart virtual machine embedded in the web browser, or as compiled JavaScript. Dart's virtual machine is also designed to run Dart programs on the server or command line. For example, the Dart project ships libraries for network IO, files, and directories.
Browser adoption
Dart compiles to modern JavaScript, allowing Dart apps to run on the modern web. However, there is a special version of Chromium that embeds the Dart virtual machine.[7] This enables this browser to run Dart programs without their first being compiled to JavaScript.
As of May 2012, Microsoft Internet Explorer, Mozilla Firefox, Opera Software's Opera browser, and Apple Safari do not have plans to implement support for Dart.
Example
The famous Hello World example:
main() { print('Hello World!'); }
A function to calculate the nth Fibonacci number:
int fib(int n) => (n > 1) ? (fib(n - 1) + fib(n - 2)) : n; main() { print('fib(20) = ${fib(20)}'); }
A simple class:
// 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. Point.origin() : x = 0, y = 0; // A method. num distanceTo(Point other) { var dx = x - other.x; var dy = y - other.y; return sqrt(dx * dx + dy * dy); } } // All dart programs start with main() main() { // Instantiate point objects. var p1 = new Point(10, 10); var p2 = new Point.origin(); var distance = p1.distanceTo(p2); print(distance); }
Criticism
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."[8]
Apple engineer Oliver Hunt, working on the WebKit project (which powers both Safari and Google's own Chrome browser) has 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).[9]
[...] 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.[10]
Mozilla's Brendan Eich, who developed the JavaScript language, has stated:[11]
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, when asked about Dart during his Programming Style and Your Brain lecture, replied[12]:
So, I've thought for a long time ... if I could take a clean sheet of paper and write [a new language] that retains all the goodness of [Javascript] ... I would not have come up with anything like Dart.
See also
- CoffeeScript
- Fantom
- Go (programming language)
- Google Web Toolkit
- HaXe, another programming language that can be trans-compiled to Javascript
- Opa
- TypeScript Open source, Javascript-like Programming Language from Microsoft[13]
References
- ^ Dart Language Specification
- ^ a b c Miller, Mark S. (November 16, 2010). ""Future of Javascript" doc from our internal "JavaScript Summit" last week". [email protected] mailing list. https://gist.github.com/1208618. Retrieved 2012-01-22. Leaked internal Google email.
- ^ Presentation: "Opening Keynote: Dart, a new programming language for structured web programming" - GOTO Aarhus 2011 conference. Planned official presentation of the Dart language, on October 10.
- ^ Why Dart?
- ^ Google Releases Dart Editor for Windows, Mac OS X, and Linux
- ^ http://plugins.intellij.net/plugin/?idea&id=6351
- ^ http://www.dartlang.org/dartium/
- ^ JavaScript Team (Shanku Niyogi, Amanda Silver, John Montgomery, Luke Hoban, Steve Lucco) (November 22, 2011). "Evolving ECMAScript". IEBlog. Microsoft. https://blogs.msdn.com/themes/blogs/generic/post.aspx?WeblogApp=ie&y=2011&m=11&d=22&WeblogPostName=evolving-ecmascript&GroupKeys=. Retrieved 2012-01-22.
- ^ Hunt, Oliver (13:36:26 PST, 5 December 2011). "WebKit branch to support multiple VMs (e.g., Dart)". webkit-dev mailing list. https://lists.webkit.org/pipermail/webkit-dev/2011-December/018787.html. Retrieved 2012-01-22.
- ^ Hunt, Oliver (23:24:43 PST, 5 December 2011). "WebKit branch to support multiple VMs (e.g., Dart)". webkit-dev mailing list. https://lists.webkit.org/pipermail/webkit-dev/2011-December/018813.html. Retrieved 2012-01-22.
- ^ Eich, Brendan (2011-09-10). ""Even Brendan Eich admitted...". As if I would not expect, nay demand, that Gila...". Hacker News. Y Combinator. https://news.ycombinator.com/item?id=2982949. Retrieved 2012-01-22.
- ^ ""Your Brain and Programming"". http://www.youtube.com/watch?v=taaEzHI9xyY.
- ^ http://www.typescriptlang.org/
External links
- Official website
- Dart FAQ
- Schuster, Werner (10 October 2011). "Google Dart Language and Tools Announced - Dynamic Language, Optionally Typed, Familiar Syntax". InfoQ. http://www.infoq.com/news/2011/10/google-dart-language. Retrieved 2011-12-04.
- A Walk on the Dart Side: A Quick Tour of Dart (2 November 2011) — Lecture given at Stanford University by Google software engineer Gilad Bracha (video archive, YouTube, transcript).
- vieiro (10 December 2011). "Google's Dart announced". Lambda the Ultimate. http://lambda-the-ultimate.org/node/4377.