Dart (programming language)
|Paradigm||Multi-paradigm: scripting, object-oriented (class-based), imperative, reflective, functional, garbage-collected|
|Designed by||Lars Bak and Kasper Lund|
|First appeared||October 10, 2011|
2.4.0 / June 19, 2019
2.5.0-dev.0.0 / June 20, 2019
|Typing discipline||1.x: Optional, 2.x: Static|
|Dart VM, dart2js, DDC, Flutter|
Dart is a client-optimized programming language for fast apps on multiple platforms. It is developed by Google and is used to build mobile, desktop, backend and web applications.
Dart was unveiled at the GOTO conference in Aarhus, Denmark, October 10–12, 2011. The project was founded by Lars Bak and Kasper Lund. Dart 1.0 was released on November 14th, 2013. In August 2018, Dart 2.0 was released, with language changes including a sound type system.
There are three main ways to run Dart code:
- The Dart software development kit (SDK) ships with a stand-alone Dart VM, allowing Dart code to run in a command-line interface environment. As the language tools included in the Dart SDK are written mostly in Dart, the stand-alone Dart VM is a critical part of the SDK. These tools include the dart2js compiler and a package manager called pub. Dart ships with a complete standard library allowing users to write fully working system apps, such as custom web servers.
- Ahead-of-time compiled
- Dart code can be AOT-compiled into machine code (native instruction sets). Apps built with Flutter, a mobile app SDK built with Dart, are deployed to app stores as AOT-compiled Dart code.
To achieve concurrency, Dart uses isolates, which are independent workers that do not share memory, but instead use message passing. This is similar to Erlang processes (see also Actor model) . Every Dart program uses at least one isolate, which is the main isolate. Since Dart 2 the Dart web platform no longer supports isolates, and suggests developers use Web Workers instead.
Snapshots are a core part of the Dart VM. Snapshots are files which store objects and other runtime data.
- Script snapshots
- Dart programs can be compiled into snapshot files. These files contain all of the program code and dependencies preparsed and ready to execute. This allows fast startups.
- Full snapshots
- The Dart core libraries can be compiled into a snapshot file which allows fast loading of the libraries. Most standard distributions of the main Dart VM have a prebuilt snapshot for the core libraries which is loaded at runtime.
- Object snapshots
- Dart is a very asynchronous language. With this, it uses isolates for concurrency. Since these are workers which pass messages, it needs a way to serialize a message. This is done using a snapshot, which is generated from a given object, and then this is transferred to another isolate for deserializing.
Native mobile apps
Google has introduced Flutter for native mobile app development on both Android and iOS. Flutter is a mobile app SDK, complete with framework, widgets, and tools, that gives developers a way to build and deploy mobile apps, written in Dart. Flutter works with Firebase and other mobile app SDKs, and is open source.
On August 13, 2012, Google announced the release of an Eclipse plugin for Dart development.
On April 18, 2015, Google announced that the Dart Editor would be retired in favor of the JetBrains integrated development environment (IDE), which is now the recommended IDE for the language. The Dart plugin is available for IntelliJ IDEA, PyCharm, PhpStorm and WebStorm. This plugin supports many features such as syntax highlighting, code completion, analysis, refactoring, debugging, and more. Other plugins are available for editors like Sublime Text, Atom, Emacs, Vim and Visual Studio Code.
Chrome Dev Editor
In 2013, the Chromium team began work on an open source, Chrome App-based development environment with a reusable library of GUI widgets, codenamed Spark. The project was later renamed as Chrome Dev Editor. It was built in Dart, and contained Spark which is powered by Polymer.
In June 2015, Google transferred the CDE project to GitHub as a free software project and ceased active investment in CDE. As of April 2019 Chrome Dev Editor is no longer in active development.
The Dart team created DartPad at the start of 2015, to provide an easier way to start using Dart. It is a fully online editor from which users can experiment with Dart application programming interfaces (APIs), and run Dart code. It provides syntax highlighting, code analysis, code completion, documentation, and HTML and CSS editing.
In 2013, John McCutchan announced that he had created a performant interface to single instruction, multiple data (SIMD) instruction sets for Dart.
The interface consists of two types:
- Float32×4, 4× single precision floating point values
- Uint32×4, 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 one 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.
A Hello World example:
A function to calculate the nth Fibonacci number:
A simple class:
Influences from other languages
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 makes use of isolates as a concurrency and security unit when structuring applications. 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 by Gilad Bracha (who is a member of the Dart team) and David Ungar and originally implemented in Self.
- Fantom (programming language)
- Go, another language developed by Google
- Google Web Toolkit
- Opa (programming language)