Dart
Dart programming language logo.svg
ParadigmMulti-paradigm: functional, imperative, object-oriented, reflective[1]
Designed byLars Bak and Kasper Lund
DeveloperGoogle
First appearedOctober 10, 2011; 10 years ago (2011-10-10)[2]
Stable release
2.17.5[3] Edit this on Wikidata / 22 June 2022; 4 days ago (22 June 2022)
Typing discipline1.x: Optional
2.x: Inferred[4] (static, strong)
PlatformCross-platform
OSCross-platform
LicenseBSD
Filename extensions.dart
Websitedart.dev
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 for client development,[8][9] such as for the web and mobile apps. It is developed by Google and can also be used to build server and desktop applications.

It is an object-oriented, class-based, garbage-collected language with C-style syntax.[10] It can compile to either native code or JavaScript, and supports interfaces, mixins, abstract classes, reified generics and type inference.[11]

History

Dart was unveiled at the GOTO conference in Aarhus, Denmark, October 10–12, 2011.[12] The project was founded by Lars Bak and Kasper Lund.[13] Dart 1.0 was released on November 14, 2013.[14]

Dart initially had a mixed reception and the Dart initiative has been criticized by some for fragmenting the web, due to the original plans to include a Dart VM in Chrome. Those plans were dropped in 2015 with the 1.9 release of Dart to focus instead on compiling Dart to JavaScript.[15]

Dart 2.0 was released in August 2018, with language changes including a sound type system.[16]

Dart 2.6 introduced a new extension, dart2native, which extends native compilation to the Linux, macOS, and Windows desktop platforms. Earlier developers could create new tools using only Android or iOS devices. With this extension it also becomes possible to compose a program into self-contained executables. According to company representatives, it’s no longer necessary to have the Dart SDK installed, as the self-contained executables can now start running in a few seconds. The new extension is also integrated with the Flutter toolkit, making it possible to use the compiler on small services (for example, backend support).[17][18]

Standardization

Ecma International has formed technical committee TC52[19] to work on standardizing Dart, and inasmuch as Dart can be compiled to standard JavaScript, it works effectively in any modern browser. EI approved the first version of the Dart language specification in July 2014 at its 107th General Assembly,[20] and a second edition in December 2014.[21] The latest specification is available here.

Usage

There are four ways to run Dart code:

Web
To run in mainstream web browsers, Dart relies on a source-to-source compiler to JavaScript. 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."[22] In a web browser, the code is precompiled into JavaScript using the dart2js compiler, making it compatible with all major browsers with no need for browsers to adopt it. By optimizing the compiled JavaScript output to avoid expensive checks and operations, code written in Dart can, in some cases, run faster than equivalent code handwritten in JavaScript idioms.[23]
Stand-alone
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 SDK are written mostly in Dart, the Dart VM is a critical part of it. 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.[24]
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.[25]
Native
Dart 2.6 includes the dart2native compiler to compile to self-contained, native executable code. Before Dart 2.6, this feature exposed this capability only on iOS and Android mobile devices via Flutter.[26]

Isolates

To achieve concurrency, Dart uses isolates, independent workers that do not share memory, but use message passing,[27] 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.[28]

Snapshots

Snapshots, a core part of the Dart VM, are files that store objects and other runtime data.[27]

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 is a very asynchronous language, using isolates for concurrency. Since these are workers that pass messages, it needs a way to serialize messages. This is done using a snapshot, which is generated from a given object, then transferred to another isolate for deserializing.

Native mobile apps

Google has introduced Flutter for native mobile app development on Android, iOS and Windows.[29] 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.[30] Flutter works with Firebase[31] and other mobile app SDKs, and is open source.

Compiling to JavaScript

The Dart SDK contains two Dart-to-JavaScript compilers. During development, dartdevc supports quick refresh cycles. For the final version of an app, dart2js produces deployable JavaScript.[32]

The first compiler to generate JavaScript from Dart code was dartc, but it was deprecated. The second Dart-to-JavaScript compiler was Frog. It was written in Dart, but never implemented the full semantics of the language. The third Dart-to-JavaScript compiler was dart2js. An evolution of earlier compilers, dart2js is written in Dart and intended to implement the full Dart language specification and semantics.

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

Editors

On November 18, 2011, Google released Dart Editor, an open-source program based on Eclipse components, for macOS, Windows, and Linux-based operating systems.[35] 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.[36]

On April 18, 2015, Google announced that the Dart Editor would be retired in favor of the JetBrains integrated development environment (IDE),[37] which is now the recommended IDE for the language. The Dart plugin[38] 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.[39]

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.[40] The project was later renamed as Chrome Dev Editor.[41] It was built in Dart, and contained Spark which is powered by Polymer.[42]

In June 2015, Google transferred the CDE project to GitHub as a free software project and ceased active investment in CDE.[43] As of April 2019 Chrome Dev Editor is no longer in active development.[44]

DartPad

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.[45]

SIMD

In 2013, John McCutchan announced[46][non-primary source needed] that he had created a performant interface to single instruction, multiple data (SIMD) instruction sets for Dart.

The interface consists of two types:

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.

Example

A Hello, World! example:

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

A function to calculate the nth Fibonacci number:

int fib(int n) => (n > 2) ? (fib(n - 1) + fib(n - 2)) : 1;
// A Fibonacci function implementation with a conditional operator in Dart
// This code is read as:
//  given an integer n,
//  if n > 2, return fib(n - 1) + fib(n - 2); 
//  otherwise, return the integer 1 as result

void main() {
  print('fib(20) = ${fib(20)}');
}

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

Dart is a descendant of the ALGOL language family,[47] 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][48] and Ruby.

Dart makes use of isolates as a concurrency and security unit when structuring applications.[49] 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[50] by Gilad Bracha (who was a member of the Dart team) and David Ungar and originally implemented in Self.

See also

References

  1. ^ Kopec, David (30 June 2014). Dart for Absolute Beginners. p. 56. ISBN 9781430264828. Retrieved 24 November 2015.
  2. ^ Bak, Lars (10 October 2011). "Dart: a language for structured web programming". Google Code Blog. Retrieved 31 January 2016.
  3. ^ https://github.com/dart-lang/sdk/releases/tag/2.17.5.
  4. ^ "The Dart type system". dart.dev.
  5. ^ "Web Languages and VMs: Fast Code is Always in Fashion. (V8, Dart) - Google I/O 2013". YouTube. Retrieved 22 December 2013.
  6. ^ "The Dart Team Welcomes TypeScript". Retrieved 22 February 2020.
  7. ^ "Dart SDK Tags". GitHub.
  8. ^ "Dart overview". dart.dev. Retrieved 2021-04-06.
  9. ^ "Dart programming language". dart.dev. Retrieved 2021-04-06. A programming language optimized for building user interfaces with features such as the spread operator for expanding collections, and collection if for customizing UI for each platform
  10. ^ "A Tour of the Dart Language". dart.dev. Retrieved 2018-08-09.
  11. ^ "The Dart type system". dart.dev.
  12. ^ "Dart, a new programming language for structured web programming", GOTO conference (presentation) (opening keynote), Århus conference, 2011-10-10
  13. ^ Ladd, Seth. "What is Dart". What is Dart?. O'Reilly. Retrieved August 16, 2014.
  14. ^ "Dart 1.0: A stable SDK for structured web apps". news.dartlang.org. Retrieved 2018-08-08.
  15. ^ Seth Ladd. "Dart News & Updates". dartlang.org.
  16. ^ Moore, Kevin (2018-08-07). "Announcing Dart 2 Stable and the Dart Web Platform". Dart. Retrieved 2018-08-08.
  17. ^ "Dart 2.5 brings native compilation to the desktop". Infoworld. 20 November 2019. Retrieved 2019-11-28.
  18. ^ "Dart 2.6 released with dart2native". SDtimes. 7 November 2019. Retrieved 2019-11-28.
  19. ^ "TC52 - Dart". Archived from the original on 2016-08-02. Retrieved 2013-12-16.
  20. ^ Anders Thorhauge Sandholm. "Dart News & Updates". dartlang.org.
  21. ^ Anders Thorhauge Sandholm. "Dart News & Updates". dartlang.org.
  22. ^ "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.
  23. ^ "JavaScript as a compilation target: Making it fast" (PDF). Dartlang.org. Archived from the original (PDF) on 2016-07-02. Retrieved 2013-08-18.
  24. ^ "An Introduction to the dart:io Library". Dartlang.org. Retrieved 2013-07-21.
  25. ^ "Flutter FAQ". docs.flutter.dev. How does Flutter run my code on iOS?. Retrieved 2022-04-07.
  26. ^ "Announcing Dart 2.6 with dart2native: Compile Dart to self-contained, native executables". 8 November 2019. Retrieved 2019-12-06.
  27. ^ a b "The Essence of Google Dart: Building Applications, Snapshots, Isolates". InfoQ. Retrieved 2021-08-29.
  28. ^ Moore, Kevin (February 23, 2018). "Dart2 Breaking Change: Removing web support for dart:mirrors and dart:isolate". Google Groups.
  29. ^ "Flutter - Beautiful native apps in record time". flutter.dev.
  30. ^ "FAQ". flutter.dev. Retrieved 2021-08-29.
  31. ^ "Firebase". flutter.dev. Retrieved 2021-08-29.
  32. ^ "Deployment". angulardart.dev.
  33. ^ Ladd, Seth (2013-03-28). "Dart News & Updates: Why dart2js produces faster JavaScript code from Dart". News.dartlang.org. Retrieved 2013-07-21.
  34. ^ "Dart Performance". Dartlang.org. Archived from the original on 2017-01-03. Retrieved 2013-07-21.
  35. ^ "Google Releases Dart Editor for Windows, Mac OS X, and Linux". Archived from the original on 2013-12-03. Retrieved 2011-11-29.
  36. ^ "Dart plugin for Eclipse is Ready for Preview".
  37. ^ Ladd, Seth (2015-04-30). "The present and future of editors and IDEs for Dart". Dart News & Updates. Retrieved 2015-05-18.
  38. ^ "JetBrains Plugin Repository : Dart". Plugins.intellij.net. Retrieved 2013-07-21.
  39. ^ "Dart Tools". dart.dev. Retrieved 2016-11-15.
  40. ^ Beaufort, François. "The chromium team is currently actively working".
  41. ^ "A Chrome app based development environment". GitHub. 26 October 2021.
  42. ^ "Spark, A Chrome App from Google is an IDE for Your Chromebook". November 22, 2013.
  43. ^ Saroop, Sri. "Chrome Dev Editor: Announcements".
  44. ^ "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.
  45. ^ Ladd, Seth (2015-05-06). "Announcing DartPad: A friction-free way to explore Dart code". Dart News & Updates. Retrieved 2015-05-18.
  46. ^ "Bringing SIMD to the web via Dart" (PDF). Archived from the original (PDF) on 2016-07-02.
  47. ^ "Algol Family". c2.com.
  48. ^ Bracha, Gilad; Griswold, David (September 1996). "Extending the Smalltalk Language with Mixins" (PDF). OOPSLA Workshop. OOPSLA.
  49. ^ "The Essence of Google Dart: Building Applications, Snapshots, Isolates". InfoQ.
  50. ^ Bracha, Gilad; Ungar, David (2004). "Mirrors: design principles for meta-level facilities of object-oriented programming languages" (PDF). ACM SIGPLAN Notices. ACM. 39 (10): 331–344. doi:10.1145/1035292.1029004. Retrieved 15 February 2014.

Bibliography