Content deleted Content added
Fix rendering of stable release date Tags: Mobile edit Mobile web edit |
|||
(42 intermediate revisions by 30 users not shown) | |||
Line 21:
| implementations=Dart VM, dart2native, dart2js, DDC, [[Flutter (software)|Flutter]]
| dialects=
| influenced by=[[C (programming language)|C]], [[C++]], [[C Sharp (programming language)|C#]], [[Erlang (programming language)|Erlang]], [[Java (programming language)|Java]], [[JavaScript]], [[Ruby (programming language)|Ruby]], [[Smalltalk]], [[Strongtalk]],<ref>{{cite web|title=Web Languages and VMs: Fast Code is Always in Fashion. (V8, Dart) - Google I/O 2013|website=[[YouTube]]|date=16 May 2013 |url=https://www.youtube.com/watch?v=huawCRlo9H4&t=30m10s|access-date=22 December 2013}}</ref> [[TypeScript]]<ref>{{cite web|title=The Dart Team Welcomes TypeScript|date=10 September 2019 |url=https://news.dartlang.org/2012/10/the-dart-team-welcomes-typescript.html|access-date=22 February 2020}}</ref>
| influenced=
| programming language=
Line 34:
'''Dart''' is a [[programming language]] designed by [[Lars Bak (computer programmer)|Lars Bak]] and Kasper Lund and developed by [[Google]].<ref>{{Cite web |title=A Bit About Dart - Learn Dart: First Step to Flutter |url=https://www.educative.io/courses/learn-dart-first-step-to-flutter/g7kmn5r74ok |access-date=2023-06-20 |website=Educative: Interactive Courses for Software Developers |language=en}}</ref> It can be used to develop [[Web application|web]] and [[mobile app]]s as well as [[Server (computing)|server]] and [[Application software|desktop applications]].
Dart is an [[Object-oriented programming|object-oriented]], [[Class-based programming|class-based]], [[Garbage collection (computer science)|garbage-collected]] language with [[C (programming language)|C]]-style [[Syntax (programming languages)|syntax]].<ref>{{Cite web|url=https://dart.dev/guides/language/language-tour#important-concepts|title=A Tour of the Dart Language|website=dart.dev|access-date=2018-08-09}}</ref> It can [[compiler|compile]] to [[machine code]], [[JavaScript]], or [[WebAssembly]]. It supports [[Interface (object-oriented programming)|interfaces]], [[mixin]]s, [[abstract class]]es, [[Reification (computer science)|reified]] [[Generic programming|generics]] and [[type inference]].<ref name="The Dart type system"/>
==History==
Line 43:
Dart 2.0 was released in August 2018 with language changes including a type system.<ref>{{Cite web|url=https://medium.com/dartlang/dart-2-stable-and-the-dart-web-platform-3775d5f8eac7|title=Announcing Dart 2 Stable and the Dart Web Platform|last=Moore|first=Kevin|date=2018-08-07|website=Dart|access-date=2018-08-08}}</ref>
In November 2019, Dart 2.6 introduced a new extension, <code>dart2native</code>. This extended native compilation to the Linux, macOS, and Windows desktop platforms.<ref>{{Cite web |title=Dart language evolution |url=https://dart.dev/guides/language/evolution |access-date=2023-06-20 |website=dart.dev |language=en}}</ref> 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.<ref>{{Cite web |title=Dart overview |url=https://dart.dev/overview.html |access-date=2023-05-12 |website=dart.dev |language=en }}{{Dead link|date=March 2024 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> The [[Flutter (software)|Flutter]] toolkit integrates Dart, so it can compile on small services like backend support.<ref>{{Cite web|url=https://www.infoworld.com/article/3454623/dart-26-brings-native-compilation-to-the-desktop.html|title=Dart 2.5 brings native compilation to the desktop|website=Infoworld|date=20 November 2019|access-date=2019-11-28}}</ref><ref>{{Cite web|url=https://sdtimes.com/goog/dart-2-6-released-with-dart2native/|title=Dart 2.6 released with dart2native|website=SDtimes|date=7 November 2019|access-date=2019-11-28}}</ref>
Dart 3.0 was released in May 2023<ref>{{Cite web |title=Dart language evolution |url=https://dart.dev/guides/language/evolution |access-date=2024-01-09 |website=dart.dev |language=en}}</ref> with changes to the type system to require sound null safety. This release included new features like records, patterns,<ref>{{Cite web |title=Patterns |url=https://dart.dev/language/patterns.html |access-date=2023-05-12 |website=dart.dev |language=en }}{{Dead link|date=March 2024 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> and class modifiers.<ref>{{Cite web
Dart == Specification ==
Line 56 ⟶ 58:
Developers can deploy Dart apps in six ways:
{| class="wikitable sortable"
|+Dart deployment methods
!Deployment type
Line 67 ⟶ 69:
|JavaScript
|Browser
| {{No}}
| {{No}}
|Slow
|Fast
|-
|WebAssembly<ref
|Browser
| {{No}}
| {{No}}
|Slow
|Fast
Line 81 ⟶ 83:
|Self-contained executable
|macOS, Windows, Linux
| {{Yes}}
| {{No}}
|Slow
|Fast
Line 88 ⟶ 90:
|Ahead-of-time module
|macOS, Windows, Linux
| {{Yes}}
| {{No}}
|Slow
|Fast
Line 95 ⟶ 97:
|Just-in-time module
|macOS, Windows, Linux
| {{Yes}}
| {{Yes}}
|Fast
|Slow
Line 102 ⟶ 104:
|Portable module
|macOS, Windows, Linux
| {{No}}
| {{Yes}}
|Fast
|Slow
Line 109 ⟶ 111:
=== Deploying to the web ===
Dart 3 can deploy apps to the web as either JavaScript or WebAssembly apps.
==== JavaScript ====
The first Dart-to-JavaScript compiler was <code>dartc</code>. It was deprecated in Dart 2.0. :The fourth Dart-to-JavaScript compiler is <code>dartdevc</code>.<ref>{{Cite web |title=dartdevc: The Dart development compiler |url=https://dart.dev/tools/dartdevc.html |access-date=2023-05-13 |website=dart.dev |language=en}}</ref> 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 the <code>dart2js</code> compiler,<ref>{{cite web |last=Ladd |first=Seth |date=2013-03-28 |title=Dart News & Updates: Why dart2js produces faster JavaScript code from Dart |url=http://news.dartlang.org/2013/03/why-dart2js-produces-faster-javascript.html |access-date=2013-07-21 |website=News.dartlang.org.}}</ref> stating that it now runs faster than handwritten JavaScript on [[V8 (JavaScript engine)|Chrome's V8 JavaScript engine]] for the DeltaBlue benchmark.<ref>{{cite web |title=Dart Performance |url=http://www.dartlang.org/performance/ |url-status=dead |archive-url=https://web.archive.org/web/20170103041945/http://www.dartlang.org/performance/ |archive-date=2017-01-03 |access-date=2013-07-21 |website=Dartlang.org.}}</ref>▼
The third Dart-to-JavaScript compiler is <code>dart2js</code>. Introduced in Dart 2.0,<ref>{{Cite web |last=Moore |first=Kevin |date=2018-08-08 |title=Announcing Dart 2 Stable and the Dart Web Platform |url=https://medium.com/dartlang/dart-2-stable-and-the-dart-web-platform-3775d5f8eac7 |access-date=2023-05-13 |website=Dart |language=en}}</ref> the Dart-based <code>dart2js</code> 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 [[Minification (programming)|minified JavaScript]].
:Prior to Dart 2.18, both <code>dart2js</code> and <code>dartdevc</code> 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. The <code>webdev serve</code> command calls the <code>dartdevc</code> compiler. The <code>webdev build</code> command calls the <code>dart2js</code> compiler. ▼
:The Dart SDK compiles to JavaScript in two ways.▼
▲
:To debug code, run <code>webdev serve</code> to compile a larger JavaScript file with human-readable code. Dart-generated JavaScript can be debugged using [[Google Chrome|Chrome]] only.<syntaxhighlight lang="shell">▼
▲
▲
<syntaxhighlight lang="text">
$ cd <dart_app_directory>
$ webdev serve [--debug] [-o <target.js>]
</syntaxhighlight>To create production apps, run <code>webdev build</code> to compile a minified JavaScript file.
<syntaxhighlight lang="text">
▲</syntaxhighlight>To create production apps, run <code>webdev build</code> to compile a minified JavaScript file.<syntaxhighlight lang="shell">
$ cd <dart_app_directory>
$ webdev build [-o <target.js>]
</syntaxhighlight>
==== WebAssembly ====
=== Deploying to native platforms ===
Line 135 ⟶ 146:
==== Self-contained executable ====
$ dart compile exe <source.dart> -o <target_app>▼
<syntaxhighlight lang="console">
Generated: <target_app>
$ ./
</syntaxhighlight>
==== Ahead-of-time module ====
<syntaxhighlight lang=" $ dart compile aot-snapshot
Generated <target_app.aot>
$ dartaotruntime
</syntaxhighlight>
==== Just-in-time module ====
<syntaxhighlight lang=" $ dart compile jit-snapshot
Compiling <source.dart> to jit-snapshot file <target_app.jit>
Hello world!
$ dart run
Hello world!
</syntaxhighlight>
==== Dart kernel module ====
<syntaxhighlight lang=" $ dart compile kernel
Compiling <source.dart> to kernel file <target_app
$ dart run
</syntaxhighlight>
== Concurrency ==
To achieve [[Concurrency (computer science)|concurrency]], Dart uses isolated, independent workers that do not share memory, but use [[message passing]],<ref name=":0">{{Cite web|title=The Essence of Google Dart: Building Applications, Snapshots, Isolates|url=https://www.infoq.com/articles/google-dart/|access-date=2021-08-29|website=InfoQ|language=en}}</ref>
== Null safety ==
Starting with Dart 2.12, Dart introduced sound [[Void safety|null safety]].<ref>{{Cite web |last=Hracek |first=Filip |date=2020-06-10 |title=Announcing sound null safety |url=https://medium.com/dartlang/announcing-sound-null-safety-defd2216a6f3 |access-date=2023-05-12 |website=Dart |language=en}}</ref> 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
==Data storage==
Line 195 ⟶ 211:
===DartPad===
[[File:DartPad screenshot.webp|thumb|DartPad screenshot]]
To provide an easier way to start using Dart, the Dart team created [https://dartpad.dev DartPad] at the start of 2015. This [[Online integrated development environment|online
== Development tools ==
Line 208 ⟶ 225:
<syntaxhighlight lang="dart">
void main() {
print('Hello, World!');
}
</syntaxhighlight>
A simple [[for-loop]]:<ref>{{Cite web | title=Loops in Dart {{!}} Fluter World {{!}} Dart and Flutter Tutorials | url=https://www.flutterworld.tech/tutorials/dart-tutorials/dart-basics/loops-in-dart/#for-loop | access-date=2024-01-12 | archive-date=2024-01-13 | archive-url=https://web.archive.org/web/20240113210803/https://www.flutterworld.tech/tutorials/dart-tutorials/dart-basics/loops-in-dart/#for-loop | url-status=dead }}</ref>
<syntaxhighlight lang="dart">
void main() {
for (
print(i);
}
}
</syntaxhighlight>
Line 226 ⟶ 243:
<syntaxhighlight lang="dart">
void main() {
print('fibonacci($i) = ${fibonacci(i)}');
}
/// Computes the nth Fibonacci number.
int fibonacci(int n) {
return n < 2 ? n : (fibonacci(n - 1) + fibonacci(n - 2));
}
Line 247 ⟶ 264:
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():
// A method.
num distanceTo(Point other) {
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
// an optional word
}
// All Dart programs start with main().
void main() {
// Instantiate point objects.
print(p1.magnitude);
print(distance);
}
</syntaxhighlight>
==Influences from other languages==
Dart belongs to the [[ALGOL]] language family.<ref>{{cite web|url=http://c2.com/cgi/wiki?AlgolFamily|title=Algol Family|work=c2.com}}</ref>{{
The [[Method cascading|method cascade]] syntax was adopted from Smalltalk.<ref>{{Cite web |title=Method Cascades in Dart |date=10 September 2019 |url=https://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html |access-date=2023-05-13 |language=en}}</ref> This syntax provides a shortcut for invoking several methods one after another on the same object.
Line 303 ⟶ 319:
| journal=OOPSLA Workshop
| publisher=OOPSLA
}}{{Dead link|date=August 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref><ref>{{Cite web |last=Ladd |first=Seth |date=November 13, 2011 |title=Transcription of A Quick Tour of Dart by Gilad Bracha |url=http://blog.sethladd.com/2011/11/transcription-of-quick-tour-of-dart-by.html |access-date=2023-05-13 |language=en}}</ref> and [[Ruby (programming language)|Ruby]].
Dart makes use of isolates as a concurrency and security unit when structuring applications.<ref>{{cite web|url=http://www.infoq.com/articles/google-dart/|title=The Essence of Google Dart: Building Applications, Snapshots, Isolates|work=InfoQ}}</ref> The Isolate concept builds upon the [[Actor model]] implemented in Erlang.<ref>{{Cite web |title=Fearless concurrency: how Clojure, Rust, Pony, Erlang and Dart let you achieve that. - Renato Athaydes |url=https://sites.google.com/a/athaydes.com/renato-athaydes/posts/fearlessconcurrencyhowclojurerustponyerlanganddartletyouachievethat#TOC-The-Actor-Model-Erlang-Dart- |access-date=2023-05-13 |website=sites.google.com |archive-date=2023-05-13 |archive-url=https://web.archive.org/web/20230513052456/https://sites.google.com/a/athaydes.com/renato-athaydes/posts/fearlessconcurrencyhowclojurerustponyerlanganddartletyouachievethat#TOC-The-Actor-Model-Erlang-Dart- |url-status=dead }}</ref>
In 2004, [[Gilad Bracha]] (who was a member of the Dart team) and [[David Ungar]] first proposed Mirror API for performing controlled and secure [[Reflective programming|reflection]] in a paper.<ref>{{cite journal
Line 322 ⟶ 338:
| doi=10.1145/1035292.1029004
| access-date=15 February 2014
}}{{Dead link|date=August 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> The concept was first implemented in [[Self (programming language)|Self]].
==See also==
|