Dart (programming language): Difference between revisions

Content deleted Content added
m Added a loop example
 
(47 intermediate revisions by 33 users not shown)
Line 14:
| developer=[[Google]]
| latest release version={{Wikidata|property|reference|edit|Q406009|P348}}
| latest release date={{start date and age|
{{Wikidatawikidata|qualifier|Q406009single|P548=Q2804309|P348|P577}}}}
| latest preview date={{Start date and age|2021|12|14}}<ref name="auto">{{Cite web|url=https://github.com/dart-lang/sdk/tags|title=Dart SDK Tags|website=[[GitHub]] }}</ref>
| typing=1.x: [[Optional typing|Optional]]<br>2.x: [[Type inference|Inferred]]<ref name="The Dart type system">{{Cite web|url=https://dart.dev/guides/language/sound-dart|title=The Dart type system|website=dart.dev}}</ref> ([[static typing|static]], [[strong typing|strong]])
Line 20 ⟶ 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 33 ⟶ 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"/>{{Cite web|url=https://dart.dev/guides/language/sound-dart|title=The latest version of Dart typeis system{{Wikidata|website=dart.devproperty|reference|edit|Q406009|P348}}</ref>.
 
==History==
Line 42 ⟶ 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 |title=Class modifiers |url=https://dart.dev/language/class-modifiers/|title=Class modifiers|website=dart.dev}}</ref>

Dart 3can alsocompile previewed support forto [[WebAssembly|Web Assembly]] since version 3.4.<ref name=":3">{{Cite web |last=Thomsen |first=Michael |date=20232024-05-1014 |title=AnnouncingLanding Flutter 3.22 and Dart 3.4 at Google I/O 2024 |url=https://medium.com/dartlangflutter/announcing-dartio24-3-53f065a106355e211f708a37 |access-date=20232024-05-1217 |website=DartFlutter |language=en}}</ref>
 
== Specification ==
Line 55 ⟶ 58:
 
Developers can deploy Dart apps in six ways:
{| class="wikitable sortable"
|+Dart deployment methods
!Deployment type
Line 66 ⟶ 69:
|JavaScript
|Browser
| {{No}}
| {{No}}
|Slow
|Fast
|-
|WebAssembly<ref (preview)name=":3" /><ref name=":2">{{Cite web |last=Thomsen |first=Michael |date=2023-05-10 |title=Announcing Dart 3 |url=https://medium.com/dartlang/announcing-dart-3-53f065a10635 |access-date=2023-05-13 |website=Dart |language=en}}</ref>
|Browser
| {{No}}
| {{No}}
|Slow
|Fast
Line 80 ⟶ 83:
|Self-contained executable
|macOS, Windows, Linux
| {{Yes}}
| {{No}}
|Slow
|Fast
Line 87 ⟶ 90:
|Ahead-of-time module
|macOS, Windows, Linux
| {{Yes}}
| {{No}}
|Slow
|Fast
Line 94 ⟶ 97:
|Just-in-time module
|macOS, Windows, Linux
| {{Yes}}
| {{Yes}}
|Fast
|Slow
Line 101 ⟶ 104:
|Portable module
|macOS, Windows, Linux
| {{No}}
| {{Yes}}
|Fast
|Slow
Line 108 ⟶ 111:
 
=== Deploying to the web ===
Dart 3 can deploy apps to the web as either JavaScript or WebAssembly apps. WebAssemblyDart supportsupports iscompiling offeredto as a preview onlyWebAssembly {{as of|2024|May 2023|lc=y}}.
 
==== JavaScript ====
: To run in mainstream [[web browser]]s, 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 pureplain JavaScript.<ref name="dartlang.org">{{cite web |url=http://www.dartlang.org/slides/2012/10/jsconfeu/javascript-as-compilation-target-florian-loitsch.pdf |title=JavaScript as a compilation target: Making it fast |publisher=Dartlang.org |access-date=2013-08-18 |archive-url=https://web.archive.org/web/20160702204820/http://www.dartlang.org/slides/2012/10/jsconfeu/javascript-as-compilation-target-florian-loitsch.pdf |archive-date=2016-07-02}}</ref>

The first Dart-to-JavaScript compiler was <code>dartc</code>. It was deprecated in Dart 2.0.
 
:The second Dart-to-JavaScript compiler was frog.<ref>{{Cite web |title=Towards a single Dart to JavaScript compiler |date=10 September 2019 |url=https://news.dartlang.org/2012/02/towards-single-dart-to-javascript.html |access-date=2023-05-13 |language=en}}</ref> Written in Dart, it was introduced in 2013 and deprecated in 2020. This should not be confused with Dart Frog,<ref>{{Cite web |title=Dart Frog |url=https://dartfrog.vgv.dev/ |access-date=2023-05-13 |website=dartfrog.vgv.dev |language=en}}</ref> an open-source Dart framework for building backend systems from [[Very Good Ventures]].
:The thirdsecond Dart-to-JavaScript compiler iswas <code>dart2js</code>frog. Introduced in Dart 2.0,<ref>{{Cite web |lasttitle=MooreTowards |first=Kevina |date=2018-08-08 |title=Announcingsingle Dart 2to StableJavaScript andcompiler the|date=10 DartSeptember Web Platform2019 |url=https://mediumnews.com/dartlang.org/dart2012/02/towards-2-stable-and-thesingle-dart-webto-platform-3775d5f8eac7javascript.html |access-date=2023-05-13 |website=Dart |language=en}}</ref> theWritten in Dart-based, <code>dart2js</code>it evolvedwas fromintroduced earlierin compilers.2013 Itand intendeddeprecated toin implement2020. theThis fullshould Dartnot languagebe specificationconfused andwith semantics.Dart DevelopersFrog, usean thisopen-source compilerDart framework for productionbuilding builds.backend Itsystems compiles tofrom [[MinificationVery (programming)|minifiedGood JavaScriptVentures]].<ref>{{Cite web|url=https://thenewstack.io/dart-frog-a-frontend-language-moves-to-the-backend/|title=Dart Frog: A Frontend Language Moves to the Backend|first=Loraine|last=Lawson|date=March 2, 2023}}</ref>
 
: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.
: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 }}{{Dead link|date=April 2024 |bot=InternetArchiveBot |fix-attempted=yes }}</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>
: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">
 
: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="shell">
 
<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 ====
 
:With the Dart 3.22 release, Google announced preview support for compiling Dart code to [[WebAssembly]].<ref name=":23" /> Full support for [[WebAssembly|Wasm]] will requirerequires adoption of the WasmGC<ref>{{Citation |title=GC Proposal for WebAssembly |date=2023-05-12 |url=https://github.com/WebAssembly/gc/blob/5431d631547c8af09a6377e29fee5126219f33c5/proposals/gc/Overview.md |access-date=2023-05-13 |publisher=WebAssembly}}</ref> feature into the Wasm standard. Chrome, 119<ref>{{Cite web |title=WebAssembly Garbage Collection (WasmGC) now enabled by default in Chrome Platform{{!}} StatusBlog |url=https://chromestatusdeveloper.chrome.com/featureblog/6062715726462976wasmgc |access-date=20232024-05-1317 |website=chromestatus.comChrome for Developers |language=en}}</ref> supports WasmGC. [[Firefox]],<ref>{{Cite web |date=2023-02-16 |title=SpiderMonkey Newsletter (Firefox 110-111) |url=https://spidermonkey.dev/blog/2023/02/16/newsletter-firefox-110-111.html |access-date=2023-05-13 |website=SpiderMonkey JavaScript/WebAssembly Engine |language=en-US}}</ref> 120 and later could support WasmGC, but a current bug is blocking compatibility.<ref>{{Cite web |title=1788206 - OffscreenCanvas.transferToImageBitmap incurs a copy |url=https://bugzilla.mozilla.org/show_bug.cgi?id=1788206 |access-date=2024-05-17 |website=bugzilla.mozilla.org |language=en}}</ref> [[Safari (web browser)|Safari]]<ref>{{Cite web |title=Safari Technology Preview 167 Release Notes |url=https://docs.developer.apple.com/documentation/safari-technology-preview-release-notes/stp-release-167 |access-date=2023-05-13 |website=Apple Developer Documentation |language=en}}</ref> and [[Microsoft Edge]] are integrating WasmGC support.
 
=== Deploying to native platforms ===
Line 134 ⟶ 146:
 
==== Self-contained executable ====
 
: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.<syntaxhighlight lang="shell">
$ dart compile exe <source.dart> -o <target_app>
<syntaxhighlight lang="console">
$ dart compile exe <"source.dart>" -o <"target_app>"
Generated: <target_app>
$ ./<target_app>
</syntaxhighlight>
 
==== Ahead-of-time module ====
:When [[AOT compilation|compiled ahead of time]],<ref>{{Cite web |last=Obinna |first=Onuoha |date=2020-04-07 |title=How does JIT and AOT work in Dart? |url=https://onuoha.medium.com/how-does-jit-and-aot-work-in-dart-cab2f31d9cb5 |access-date=2023-06-20 |website=Medium |language=en}}</ref> 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.
<syntaxhighlight lang="shellconsole">
$ dart compile aot-snapshot <"source.dart>"
Generated <target_app.aot>
$ dartaotruntime <"target_app.aot>"
</syntaxhighlight>
 
==== Just-in-time module ====
:When [[Just-in-time compilation|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.
<syntaxhighlight lang="shellconsole">
$ 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!
</syntaxhighlight>
 
==== Dart kernel module ====
: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.
<syntaxhighlight lang="shellconsole">
$ dart compile kernel <"source.dart>"
Compiling <source.dart> to kernel file <target_app>.dill>.
$ dart run <"target_app>.dill"
</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> similarlysimilar to [[Erlang (programming language)|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 worker|Web Workers]] instead.<ref>{{Cite web|url=https://groups.google.com/a/dartlang.org/d/msg/misc/djfFMNCWmkE/F7WE8a0JAwAJ|title=Dart2 Breaking Change: Removing web support for dart:mirrors and dart:isolate|last=Moore|first=Kevin|date=February 23, 2018|website=Google Groups}}</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&nbsp; 3.0, all code must follow sound null safety.
 
==Data storage==
Line 194 ⟶ 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 editorIDE]] allows developers to experiment with Dart [[application programming interface]]s (APIs) and run Dart code. It provides syntax highlighting, code analysis, code completion, documentation, and HTML and CSS editing.<ref>{{Cite web|url=http://news.dartlang.org/2015/05/announcing-dartpad-friction-free-way-to.html|title=Announcing DartPad: A friction-free way to explore Dart code|last=Ladd|first=Seth|date=2015-05-06|website=Dart News & Updates|access-date=2015-05-18}}</ref>
 
== Development tools ==
Line 207 ⟶ 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">
<ref>void main() {
for (varint i = 1; i <= 10; i++) {
print(i);
}
}
</syntaxhighlight>
Line 215 ⟶ 243:
<syntaxhighlight lang="dart">
void main() {
var int 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));
}
 
Line 236 ⟶ 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():
: x = 0, y = 0;
y = 0;
 
// A method.
num distanceTo(Point other) {
var num dx = x - other.x;
var num 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 instantiateinstantiating 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 Point p1 = Point(10, 10);
print(p1.magnitude);
var Point p2 = Point.origin();
var num distance = p1.distanceTo(p2);
print(distance);
}
 
Example of simple loop:
<ref>void main() {
for (var i = 1; i <= 10; i++) {
print(i);
}
}[https://www.flutterworld.tech/tutorials/dart-tutorials/dart-basics/loops-in-dart/#for-loop]</ref>
</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>{{NotFailed in refverification|date=September 2023}} Its members include C, Java, C#, JavaScript, and others.
 
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 299 ⟶ 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 318 ⟶ 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==