Dart (programming language)
Paradigm | Multi-paradigm: functional, imperative, object-oriented, reflective[1] |
---|---|
Designed by | Lars Bak, Kasper Lund |
Developer | |
First appeared | October 10, 2011[2] |
Stable release | 3.5.0[3] |
Typing discipline | 1.x: Optional 2.x: Inferred[4] (static, strong) |
Platform | Cross-platform |
OS | Cross-platform |
License | BSD |
Filename extensions | .dart |
Website | dart |
Major implementations | |
Dart VM, dart2native, dart2js, DDC, Flutter | |
Influenced by | |
C, C++, C#, Erlang, Java, JavaScript, Ruby, Smalltalk, Strongtalk,[5] TypeScript[6] |
Dart is a programming language designed by Lars Bak and Kasper Lund and developed by Google.[8] It can be used to develop web and mobile apps as well as server and desktop applications.
Dart is an object-oriented, class-based, garbage-collected language with C-style syntax.[9] It can compile to machine code, JavaScript, or WebAssembly. It supports interfaces, mixins, abstract classes, reified generics and type inference.[4]
History
[edit]Dart was unveiled at the GOTO conference in Aarhus, 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 Dart VM in Chrome. 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]
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] The Flutter 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 to WebAssembly since version 3.4.[22]
Specification
[edit]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 and drafts 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]
Deploying apps
[edit]The Dart software development kit (SDK) ships with a standalone Dart runtime. This allows Dart code to run in a command-line interface environment. The SDK includes tools to compile and package Dart apps.[30] Dart ships with a complete standard 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 |
Deploying to the web
[edit]Dart 3 can deploy apps to the web as either JavaScript or WebAssembly apps. Dart supports compiling to WebAssembly as of May 2024[update].
JavaScript
[edit]- To run in mainstream web browsers, Dart relies on a source-to-source compiler to JavaScript. 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 pure JavaScript.[33]
- The first Dart-to-JavaScript compiler was
dartc
. 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,[35] an open-source Dart framework for building backend systems from Very Good Ventures.
- The third Dart-to-JavaScript compiler is
dart2js
. 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 to minified JavaScript. - The fourth Dart-to-JavaScript compiler is
dartdevc
.[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 on Chrome's V8 JavaScript engine for the DeltaBlue benchmark.[39] - Prior to Dart 2.18, both
dart2js
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, run
webdev serve
to compile a larger JavaScript file with human-readable code. Dart-generated JavaScript can be debugged using Chrome only.To create production apps, run$ cd <dart_app_directory> $ webdev serve [--debug] [-o <target.js>]
webdev build
to compile a minified JavaScript file.$ cd <dart_app_directory> $ webdev build [-o <target.js>]
WebAssembly
[edit]- With the Dart 3.22 release, Google announced support for compiling Dart code to WebAssembly.[22] Full support for Wasm 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] and Microsoft Edge are integrating WasmGC support.
Deploying to native platforms
[edit]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 the Flutter framework.
Self-contained executable
[edit]- 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.
$ dart compile exe <source.dart> -o <target_app> Generated: <target_app> $ ./<target_app>
Ahead-of-time module
[edit]- When compiled ahead of time,[45] Dart code produces portable, performant, and platform-specific modules. It includes all dependent libraries and packages the app needs plus a small Dart runtime. This increases its compilation time. The compiler outputs an app specific to the architecture on which it was compiled.
$ dart compile aot-snapshot <source.dart> Generated <target_app.aot> $ dartaotruntime <target_app.aot>
Just-in-time module
[edit]- When compiled 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.
$ dart compile jit-snapshot <source.dart> Compiling <source.dart> to jit-snapshot file <target_app.jit> Hello world! $ dart run <target_app.jit> Hello world!
Dart kernel module
[edit]- 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.
$ dart compile kernel <source.dart> Compiling <source.dart> to kernel file <target_app>.dill. $ dart run <target_app>.dill
Concurrency
[edit]To achieve concurrency, Dart uses isolated, independent workers that do not share memory, but use message passing,[46] similarly to Erlang processes (also see 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.[47]
Null safety
[edit]Starting with Dart 2.12, Dart introduced sound null 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.
Data storage
[edit]Snapshot files, a core part of the Dart VM, store objects and other runtime data.[46]
- Script snapshots
- Dart programs can be compiled into snapshot files containing all of the program code and dependencies preparsed and ready to execute, allowing fast startups.
- Full snapshots
- The Dart core libraries can be compiled into a snapshot file that allows fast loading of the libraries. Most standard distributions of the main Dart VM have a prebuilt snapshot for the core libraries that is loaded at runtime.
- Object snapshots
- Dart uses snapshots to serialize messages that it passes between isolates. As a very asynchronous language, Dart uses isolates for concurrency.[49] An object generates a snapshot, transfers it to another isolate, then the isolate deserializes it.
Editors
[edit]On November 18, 2011, Google released Dart Editor, an open-source program based on Eclipse components, for macOS, Windows, and Linux-based operating systems.[50] The editor supports syntax highlighting, code completion, JavaScript compiling, running web and server Dart applications, and debugging.
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 the JetBrains integrated development environment (IDE).[52] Android Studio, IntelliJ IDEA, PyCharm, PhpStorm and WebStorm 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] including Sublime Text,[55] Atom,[56] Emacs,[57] Vim[58] and Visual Studio Code.[59]
Chrome Dev Editor
[edit]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.[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]
DartPad
[edit]To provide an easier way to start using Dart, the Dart team created DartPad at the start of 2015. This online editor allows developers to 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.[65]
Development tools
[edit]The Dart DevTools, written in Dart,[66] include debugging and performance tools.
Flutter
[edit]Google introduced Flutter for native app development. Built using Dart, C, C++ and Skia, Flutter is an open-source, multi-platform app UI framework. Prior to Flutter 2.0, developers could only target Android, 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 for Windows[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 with Firebase[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]
Example
[edit]A Hello, World! example:
void main() {
print('Hello, World!');
}
void main() {
for (var i = 1; i <= 10; i++) {
print(i);
}
}
A function to calculate the nth Fibonacci number:
void main() {
var i = 20;
print('fibonacci($i) = ${fibonacci(i)}');
}
/// Computes the nth Fibonacci number.
int fibonacci(int n) {
return n < 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' as math;
// Create a class for Point.
class Point {
// Final variables cannot be changed once they are assigned.
// Declare two instance variables.
final num x, 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.
num distanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return math.sqrt(dx * dx + dy * dy);
}
// Example of a "getter".
// Acts the same as a final variable, but is computed on each access.
num get magnitude => math.sqrt(x * x + y * y);
// Example of operator overloading
Point operator +(Point other) => Point(x + other.x, y + other.y);
// When you instantiate a class such as Point in Dart 2+, new is
// an optional word
}
// All Dart programs start with main().
void main() {
// Instantiate point objects.
var p1 = Point(10, 10);
print(p1.magnitude);
var p2 = Point.origin();
var distance = p1.distanceTo(p2);
print(distance);
}
Influences from other languages
[edit]Dart belongs to the ALGOL language family.[75][failed verification] Its members include C, Java, C#, JavaScript, and others.
The method cascade syntax was adopted from Smalltalk.[76] This syntax provides a shortcut for invoking several methods one after another on the same object.
Dart's mixins were influenced by Strongtalk[citation needed][77][78] and Ruby.
Dart makes use of isolates as a concurrency and security unit when structuring applications.[79] The Isolate concept builds upon the Actor model implemented in Erlang.[80]
In 2004, Gilad Bracha (who was a member of the Dart team) and David Ungar first proposed Mirror API for performing controlled and secure reflection in a paper.[81] The concept was first implemented in Self.
See also
[edit]- Google Web Toolkit
- TypeScript, a strongly-typed programming language that transpiles to JavaScript
- Flutter, an open-source UI software development kit for cross-platform applications
References
[edit]- ^ Kopec, David (30 June 2014). Dart for Absolute Beginners. Apress. p. 56. ISBN 9781430264828. Retrieved 24 November 2015.
- ^ Bak, Lars (10 October 2011). "Dart: a language for structured web programming". Google Code Blog. Retrieved 31 January 2016.
- ^ "Release 3.5.0". 6 August 2024. Retrieved 6 August 2024.
- ^ a b "The Dart type system". dart.dev.
- ^ "Web Languages and VMs: Fast Code is Always in Fashion. (V8, Dart) - Google I/O 2013". YouTube. 16 May 2013. Retrieved 22 December 2013.
- ^ "The Dart Team Welcomes TypeScript". 10 September 2019. Retrieved 22 February 2020.
- ^ "Dart SDK Tags". GitHub.
- ^ "A Bit About Dart - Learn Dart: First Step to Flutter". Educative: Interactive Courses for Software Developers. Retrieved 2023-06-20.
- ^ "A Tour of the Dart Language". dart.dev. Retrieved 2018-08-09.
- ^ "Dart, a new programming language for structured web programming", GOTO conference (presentation) (opening keynote), Århus conference, 2011-10-10
{{citation}}
: CS1 maint: location missing publisher (link) - ^ Ladd, Seth. "What is Dart". What is Dart?. O'Reilly. Retrieved August 16, 2014.
- ^ "Dart 1.0: A stable SDK for structured web apps". news.dartlang.org. Retrieved 2018-08-08.
- ^ Seth Ladd (10 September 2019). "Dart News & Updates". dartlang.org.
- ^ Moore, Kevin (2018-08-07). "Announcing Dart 2 Stable and the Dart Web Platform". Dart. Retrieved 2018-08-08.
- ^ "Dart language evolution". dart.dev. Retrieved 2023-06-20.
- ^ "Dart overview". dart.dev. Retrieved 2023-05-12.[permanent dead link]
- ^ "Dart 2.5 brings native compilation to the desktop". Infoworld. 20 November 2019. Retrieved 2019-11-28.
- ^ "Dart 2.6 released with dart2native". SDtimes. 7 November 2019. Retrieved 2019-11-28.
- ^ "Dart language evolution". dart.dev. Retrieved 2024-01-09.
- ^ "Patterns". dart.dev. Retrieved 2023-05-12.[permanent dead link]
- ^ "Class modifiers".
- ^ a b c Thomsen, Michael (2024-05-14). "Landing Flutter 3.22 and Dart 3.4 at Google I/O 2024". Flutter. Retrieved 2024-05-17.
- ^ "Dart Programming Language Specification, 5th edition" (PDF).
- ^ "Dart Programming Language Specification, 6th edition draft" (PDF).
- ^ "Dart language GitHub repository". GitHub.
- ^ "TC52 - Dart". Archived from the original on 2016-08-02. Retrieved 2013-12-16.
- ^ a b "ECMA-408". Ecma International. Retrieved 2023-05-12.
- ^ Anders Thorhauge Sandholm (10 September 2019). "Dart News & Updates". dartlang.org.
- ^ Anders Thorhauge Sandholm (10 September 2019). "Dart News & Updates". dartlang.org.
- ^ "Packages of publisher tools.dart.dev". Dart packages. Retrieved 2023-05-12.
- ^ "An Introduction to the dart:io Library". dart.dev. Retrieved 2013-07-21.
- ^ Thomsen, Michael (2023-05-10). "Announcing Dart 3". Dart. Retrieved 2023-05-13.
- ^ "JavaScript as a compilation target: Making it fast" (PDF). Dartlang.org. Archived from the original (PDF) on 2016-07-02. Retrieved 2013-08-18.
- ^ "Towards a single Dart to JavaScript compiler". 10 September 2019. Retrieved 2023-05-13.
- ^ "Dart Frog". dartfrog.vgv.dev. Retrieved 2023-05-13.
- ^ Moore, Kevin (2018-08-08). "Announcing Dart 2 Stable and the Dart Web Platform". Dart. Retrieved 2023-05-13.
- ^ "dartdevc: The Dart development compiler". dart.dev. Retrieved 2023-05-13.[permanent dead link]
- ^ Ladd, Seth (2013-03-28). "Dart News & Updates: Why dart2js produces faster JavaScript code from Dart". News.dartlang.org. Retrieved 2013-07-21.
- ^ "Dart Performance". Dartlang.org. Archived from the original on 2017-01-03. Retrieved 2013-07-21.
- ^ GC Proposal for WebAssembly, WebAssembly, 2023-05-12, retrieved 2023-05-13
- ^ "WebAssembly Garbage Collection (WasmGC) now enabled by default in Chrome | Blog". Chrome for Developers. Retrieved 2024-05-17.
- ^ "SpiderMonkey Newsletter (Firefox 110-111)". SpiderMonkey JavaScript/WebAssembly Engine. 2023-02-16. Retrieved 2023-05-13.
- ^ "1788206 - OffscreenCanvas.transferToImageBitmap incurs a copy". bugzilla.mozilla.org. Retrieved 2024-05-17.
- ^ "Safari Technology Preview 167 Release Notes". Apple Developer Documentation. Retrieved 2023-05-13.
- ^ Obinna, Onuoha (2020-04-07). "How does JIT and AOT work in Dart?". Medium. Retrieved 2023-06-20.
- ^ a b "The Essence of Google Dart: Building Applications, Snapshots, Isolates". InfoQ. Retrieved 2021-08-29.
- ^ Moore, Kevin (February 23, 2018). "Dart2 Breaking Change: Removing web support for dart:mirrors and dart:isolate". Google Groups.
- ^ Hracek, Filip (2020-06-10). "Announcing sound null safety". Dart. Retrieved 2023-05-12.
- ^ "Concurrency in Dart". dart.dev. Retrieved 2023-05-12.
- ^ "Google Releases Dart Editor for Windows, Mac OS X, and Linux". Archived from the original on 2013-12-03. Retrieved 2011-11-29.
- ^ "Dart plugin for Eclipse is Ready for Preview". 10 September 2019.
- ^ Ladd, Seth (2015-04-30). "The present and future of editors and IDEs for Dart". Dart News & Updates. Retrieved 2015-05-18.
- ^ "JetBrains Plugin Repository : Dart". Plugins.intellij.net. Retrieved 2013-07-21.
- ^ "Dart Tools". dart.dev. Retrieved 2016-11-15.
- ^ "Dart - Packages - Package Control". packagecontrol.io. Retrieved 2023-05-13.
- ^ "dart - Dart plugin for Atom". dart-atom.github.io. Retrieved 2023-05-13.
- ^ Trainor, Brady (2023-04-15), bradyt/dart-mode, retrieved 2023-05-13
- ^ Dart Support for Vim, Dart, 2023-05-09, retrieved 2023-05-13
- ^ "Dart - Visual Studio Marketplace". marketplace.visualstudio.com. Retrieved 2023-05-13.
- ^ Beaufort, François. "The chromium team is currently actively working".
- ^ "A Chrome app based development environment". GitHub. 26 October 2021.
- ^ "Spark, A Chrome App from Google is an IDE for Your Chromebook". November 22, 2013.
- ^ Saroop, Sri. "Chrome Dev Editor: Announcements".
- ^ "Chrome Dev Editor is a developer tool for building apps on the Chrome platform: Chrome Apps and Web Apps, in JavaScript or Dart. (NO LONGER IN ACTIVE DEVELOPMENT) - googlearchive/chromedeveditor". July 29, 2019 – via GitHub.
- ^ Ladd, Seth (2015-05-06). "Announcing DartPad: A friction-free way to explore Dart code". Dart News & Updates. Retrieved 2015-05-18.
- ^ Dart & Flutter DevTools, Flutter, 2023-05-12, retrieved 2023-05-12
- ^ Sells, Chris (2021-03-03). "What's New in Flutter 2.0". Flutter. Retrieved 2023-05-12.
- ^ Sneath, Tim (February 3, 2022). "Announcing Flutter for Windows".
- ^ Chisholm, Kevin (2022-05-12). "What's new in Flutter 3". Flutter. Retrieved 2023-05-12.
- ^ "FAQ". flutter.dev. Retrieved 2021-08-29.
- ^ "Firebase". flutter.dev. Retrieved 2021-08-29.
- ^ "Dart packages". Dart packages. Retrieved 2023-05-12.
- ^ "Flutter - IntelliJ IDEs Plugin | Marketplace". JetBrains Marketplace. Retrieved 2023-05-13.
- ^ "Loops in Dart | Fluter World | Dart and Flutter Tutorials".
- ^ "Algol Family". c2.com.
- ^ "Method Cascades in Dart". 10 September 2019. Retrieved 2023-05-13.
- ^ Bracha, Gilad; Griswold, David (September 1996). "Extending the Smalltalk Language with Mixins" (PDF). OOPSLA Workshop. OOPSLA.
- ^ Ladd, Seth (November 13, 2011). "Transcription of A Quick Tour of Dart by Gilad Bracha". Retrieved 2023-05-13.
- ^ "The Essence of Google Dart: Building Applications, Snapshots, Isolates". InfoQ.
- ^ "Fearless concurrency: how Clojure, Rust, Pony, Erlang and Dart let you achieve that. - Renato Athaydes". sites.google.com. Archived from the original on 2023-05-13. Retrieved 2023-05-13.
- ^ Bracha, Gilad; Ungar, David (2004). "Mirrors: design principles for meta-level facilities of object-oriented programming languages" (PDF). ACM SIGPLAN Notices. 39 (10). ACM: 331–344. doi:10.1145/1035292.1029004. Retrieved 15 February 2014.
Bibliography
[edit]- Walrath, Kathy; Ladd, Seth (March 7, 2012). What is Dart? (1st ed.). O'Reilly Media. p. 20. ISBN 978-14493-32327.
- Walrath, Kathy; Ladd, Seth (November 7, 2012). Dart: Up and Running (1st ed.). O'Reilly Media. p. 144. ISBN 978-1449330897.
- Buckett, Chris (December 28, 2012). Dart in Action (1st ed.). Manning Publications. p. 475. ISBN 978-1617290862.
External links
[edit]- 2011 software
- C programming language family
- Concurrent programming languages
- Dynamically typed programming languages
- Free software projects
- Google software
- JavaScript programming language family
- Object-oriented programming languages
- Programming languages created in 2011
- Scripting languages
- Software using the BSD license
- Source-to-source compilers
- Web programming