| Dart | |
|---|---|
| Paradigm | Multi-paradigm:functional,imperative,object-oriented,reflective[1] |
| Designed by | Lars Bak, Kasper Lund |
| Developer | |
| First appeared | October 10, 2011; 14 years ago (2011-10-10)[2] |
| Stable release | |
| Typing discipline | 1.x:Optional 2.x:Inferred[4] (static,strong) |
| Platform | Cross-platform |
| OS | Cross-platform |
| License | BSD |
| Filename extensions | .dart |
| Website | dart |
| Majorimplementations | |
| Dart VM, dart2native, dart2js, DDC,Flutter | |
| Influenced by | |
| C,C++,C#,Erlang,Java,JavaScript,Ruby,Smalltalk,Strongtalk,[5]TypeScript[6] | |
Dart is aprogramming language designed byLars Bak and Kasper Lund and developed byGoogle.[8] It can be used to developweb andmobile apps as well asserver anddesktop applications.
Dart is anobject-oriented,class-based,garbage-collected language withC-stylesyntax.[9] It cancompile tomachine code,JavaScript, orWebAssembly. It supportsinterfaces,mixins,abstract classes,reifiedgenerics andtype inference.[4] The latest version of Dart is 3.9.4[3]
.
Dart was unveiled at the GOTO conference inAarhus, Denmark, October 10–12, 2011.[10]Lars Bak and Kasper Lund founded the project.[11] Dart 1.0 was released on November 14, 2013.[12]
Dart had a mixed reception at first. Some criticized the Dart initiative for fragmenting the web because of plans to include a DartVM inChrome. Those plans were dropped in 2015 with the Dart 1.9 release. Focus changed to compiling Dart code to JavaScript.[13]
Dart 2.0 was released in August 2018 with language changes including a type system.[14]
In November 2019, Dart 2.6 introduced a new extension,dart2native. This extended native compilation to the Linux, macOS, and Windows desktop platforms.[15] Earlier developers could create new tools using only Android or iOS devices. With this extension, developers could deploy a program into self-contained executables. The Dart SDK doesn't need to be installed to run these self-contained executables.[16] TheFlutter toolkit integrates Dart, so it can compile on small services like backend support.[17][18]
Dart 3.0 was released in May 2023[19] with changes to the type system to require sound null safety. This release included new features like records, patterns,[20] and class modifiers.[21]
Dart can compile toWebAssembly since version 3.4.[22]
Dart released the 5th edition of its language specification on April 9, 2021.[23] This covers all syntax through Dart 2.10. A draft of the 6th edition includes all syntax through 2.13.[24]Accepted proposals for the specification anddrafts of potential features can be found in the Dart language repository on GitHub.[25]
ECMA International formed technical committee, TC52,[26] to standardize Dart. ECMA approved the first edition of the Dart language specification as ECMA-408[27] in July 2014 at its 107th General Assembly.[28] Subsequent editions were approved in December 2014,[29] June 2015, and December 2015.[27]
The Dartsoftware development kit (SDK) ships with a standalone Dart runtime. This allows Dart code to run in acommand-line interface environment. The SDK includes tools to compile andpackage Dart apps.[30] Dart ships with a completestandard library allowing users to write fully working system apps like custom web servers.[31]
Developers can deploy Dart apps in six ways:
| Deployment type | Target platform | Platform- specific | Requires Dart VM | Compile speed | Execution speed |
|---|---|---|---|---|---|
| JavaScript | Browser | No | No | Slow | Fast |
| WebAssembly[22][32] | Browser | No | No | Slow | Fast |
| Self-contained executable | macOS, Windows, Linux | Yes | No | Slow | Fast |
| Ahead-of-time module | macOS, Windows, Linux | Yes | No | Slow | Fast |
| Just-in-time module | macOS, Windows, Linux | Yes | Yes | Fast | Slow |
| Portable module | macOS, Windows, Linux | No | Yes | Fast | Slow |
Dart 3 can deploy apps to the web as either JavaScript or WebAssembly apps. Dart supports compiling to WebAssembly as of May 2024[update].
To run in mainstreamweb browsers, Dart relies on asource-to-source compiler toJavaScript. This makes Dart apps compatible with all major browsers. Dart optimizes the compiled JavaScript output to avoid expensive checks and operations. This results in JavaScript code that can run faster than equivalent code handwritten in plain JavaScript.[33]
The first Dart-to-JavaScript compiler wasdartc. It was deprecated in Dart 2.0.
The second Dart-to-JavaScript compiler was frog.[34] Written in Dart, it was introduced in 2013 and deprecated in 2020. This should not be confused with Dart Frog, an open-source Dart framework for building backend systems fromVery Good Ventures.[35]
The third Dart-to-JavaScript compiler isdart2js. Introduced in Dart 2.0,[36] the Dart-baseddart2js evolved from earlier compilers. It intended to implement the full Dart language specification and semantics. Developers use this compiler for production builds. It compiles tominified JavaScript.
The fourth Dart-to-JavaScript compiler isdartdevc.[37] Developers could use this compiler for development builds. It compiles to human-readable JavaScript. On March 28, 2013, the Dart team posted an update on their blog addressing Dart code compiled to JavaScript with thedart2js compiler,[38] stating that it now runs faster than handwritten JavaScript onChrome's V8 JavaScript engine for the DeltaBlue benchmark.[39]
Prior to Dart 2.18, bothdart2js anddartdevc could be called from the command line. Dart 2.18 folded these functions into the Dart SDK. This removed the direct command line wrappers but kept the two compilers. Thewebdev serve command calls thedartdevc compiler. Thewebdev build command calls thedart2js compiler.
The Dart SDK compiles to JavaScript in two ways.
To debug code, runwebdev serve to compile a larger JavaScript file with human-readable code. Dart-generated JavaScript can be debugged usingChrome only.
$ cd <dart_app_directory>$ webdev serve [--debug] [-o <target.js>]
To create production apps, runwebdev build to compile a minified JavaScript file.
$ cd <dart_app_directory>$ webdev build [-o <target.js>]
With the Dart 3.22 release, Google announced support for compiling Dart code toWebAssembly.[22] Full support forWasm requires adoption of the WasmGC[40] feature into the Wasm standard. Chrome 119[41] supports WasmGC.Firefox[42] 120 and later could support WasmGC, but a current bug is blocking compatibility.[43]Safari[44] andMicrosoft Edge are integrating WasmGC support.
Dart can compile to native machine code for macOS, Windows, and Linux as command line tools. Dart can compile apps with user interfaces to the web, iOS, Android, macOS, Windows, and Linux using theFlutter framework.
Self-contained executables include native machine code compiled from the specified Dart code file, its dependencies, and a small Dart runtime. The runtime handles type checking and garbage collection. The compiler produces output specific to the architecture on which the developer compiled it. This file can be distributed as any other native executable.
$dartcompileexe"source.dart"-o"target_app"Generated: <target_app>$./target_app
Whencompiled ahead of time,[45] Dart code produces performant and platform-specific modules. It includes all dependent libraries and packages the app needs. This increases its compilation time. The compiler outputs an app specific to the architecture on which it was compiled.
$dartcompileaot-snapshot"source.dart"Generated <target_app.aot>$dartaotruntime"target_app.aot"
Whencompiled just in time, Dart code produces performant modules that compile fast. This module needs the Dart VM included with the SDK to run. The compiler loads all parsed classes and compiled code into memory the first time the app runs. This speeds up any subsequent run of the app. The compiler outputs an app specific to the architecture on which it was compiled.
$dartcompilejit-snapshot"source.dart"Compiling <source.dart> to jit-snapshot file <target_app.jit>Hello world!$dartrun"target_app.jit"Hello world!
When compiled as a kernel module, Dart code produces a machine-independent format called the Dart Intermediate Representation (Dart IR). The Dart IR bytecode format can work on any architecture that has a Dart VM. This makes this format very portable and quick to compile, but less performant than other compilation outputs.
$dartcompilekernel"source.dart"Compiling <source.dart> to kernel file <target_app.dill>.$dartrun"target_app.dill"
To achieveconcurrency, Dart uses isolated, independent workers that do not share memory, but usemessage passing,[46] similar toErlang processes (also seeactor 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 useWeb Workers instead.[47]
Starting with Dart 2.12, Dart introduced soundnull safety.[48] This serves as a guarantee that variables cannot return a null value unless it has explicit permission. Null safety prevents the developer from introducing null-pointer exceptions, a common, but difficult to debug, error. With Dart 3.0, all code must follow sound null safety.
Snapshot files, a core part of the Dart VM, store objects and other runtime data.[46]
On November 18, 2011, Google releasedDart Editor, an open-source program based onEclipse components, formacOS,Windows, andLinux-basedoperating systems.[50] The editor supportssyntax highlighting,code completion, JavaScript compiling, running web and server Dart applications, anddebugging.
On August 13, 2012, Google announced the release of an Eclipse plugin for Dart development.[51]
On April 18, 2015, Google retired the Dart Editor in favor of theJetBrainsintegrated development environment (IDE).[52]Android Studio,IntelliJ IDEA,PyCharm,PhpStorm andWebStorm support a Dart plugin.[53] This plugin supports many features such as syntax highlighting, code completion, analysis, refactoring, debugging, and more. Other editors include plugins for Dart[54] includingSublime Text,[55]Atom,[56]Emacs,[57]Vim[58] andVisual Studio Code.[59]
In 2013, the Chromium team began work on an open source,Chrome App-based development environment with a reusable library ofGUI widgets, codenamed Spark.[60] The project was later renamed as Chrome Dev Editor.[61] Built in Dart, it contained Spark which is powered by Polymer.[62]
In June 2015, Google transferred the CDE project to GitHub as a free software project and ceased active investment in CDE.[63] The Chrome Dev Editor project was archived on April 24, 2021.[64]

To provide an easier way to start using Dart, the Dart team createdDartPad at the start of 2015. Thisonline IDE allows developers to experiment with Dartapplication programming interfaces (APIs) and run Dart code. It provides syntax highlighting, code analysis, code completion, documentation, and HTML and CSS editing.[65]
The Dart DevTools, written in Dart,[66] include debugging and performance tools.
Google introducedFlutter for native app development. Built using Dart, C, C++ andSkia, Flutter is an open-source, multi-platform app UI framework. Prior to Flutter 2.0, developers could only targetAndroid,iOS and the web. Flutter 2.0 released support for macOS, Linux, and Windows as a beta feature.[67] Flutter 2.10 released with production support forWindows[68] and Flutter 3 released production support for all desktop platforms.[69] It provides a framework, widgets, and tools. This framework gives developers a way to build and deploy mobile, desktop, and web apps.[70] Flutter works withFirebase[71] and supports extending the framework through add-ons called packages. These can be found on their package repository, pub.dev.[72] JetBrains also supports a Flutter plugin.[73]
AHello, World! example:
voidmain(){print('Hello, World!');}
voidmain(){for(inti=1;i<=10;i++){print(i);}}
A function to calculate the nthFibonacci number:
voidmain(){inti=20;print('fibonacci($i) =${fibonacci(i)}');}/// Computes the nth Fibonacci number.intfibonacci(intn){returnn<2?n:(fibonacci(n-1)+fibonacci(n-2));}
A simple class:
// Import the math library to get access to the sqrt function.// Imported with `math` as name, so accesses need to use `math.` as prefix.import'dart:math'asmath;// Create a class for Point.classPoint{// Final variables cannot be changed once they are assigned.// Declare two instance variables.finalnumx,y;// A constructor, with syntactic sugar for setting instance variables.// The constructor has two mandatory parameters.Point(this.x,this.y);// A named constructor with an initializer list.Point.origin():x=0,y=0;// A method.numdistanceTo(Pointother){numdx=x-other.x;numdy=y-other.y;returnmath.sqrt(dx*dx+dy*dy);}// Example of a "getter".// Acts the same as a final variable, but is computed on each access.numgetmagnitude=>math.sqrt(x*x+y*y);// Example of operator overloadingPointoperator+(Pointother)=>Point(x+other.x,y+other.y);// When instantiating a class such as Point in Dart 2+, new is// an optional word}// All Dart programs start with main().voidmain(){// Instantiate point objects.Pointp1=Point(10,10);print(p1.magnitude);Pointp2=Point.origin();numdistance=p1.distanceTo(p2);print(distance);}
Dart belongs to theALGOL language family.[75][failed verification] Its members include C, Java, C#, JavaScript, and others.
Themethod cascade syntax was adopted from Smalltalk.[76] This syntax provides a shortcut for invoking several methods one after another on the same object.
Dart'smixins were influenced byStrongtalk[citation needed][77][78] andRuby.
Dart makes use of isolates as a concurrency and security unit when structuring applications.[79] The Isolate concept builds upon theActor model implemented in Erlang.[80]
In 2004,Gilad Bracha (who was a member of the Dart team) andDavid Ungar first proposed Mirror API for performing controlled and securereflection in a paper.[81] The concept was first implemented inSelf.
{{citation}}: CS1 maint: location missing publisher (link)