Dart (programming language): Difference between revisions

Content deleted Content added
m Fixed the formatting of several paragraphs
 
(11 intermediate revisions by 6 users not shown)
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">{{Cite web|url=https://dart.dev/guides/language/sound-dart|title=The Dart type system|website=dart.dev}}</ref> The latest version of Dart is {{Wikidata|property|reference|edit|Q406009|P348}}.
 
==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 |title=Class modifiers |url=https://dart.dev/language/class-modifiers/|title=Class modifiers|website=dart.dev}}</ref>
 
Dart can compile to [[WebAssembly]] since version 3.4.<ref name=":3">{{Cite web |last=Thomsen |first=Michael |date=2024-05-14 |title=Landing Flutter 3.22 and Dart 3.4 at Google I/O 2024 |url=https://medium.com/flutter/io24-5e211f708a37 |access-date=2024-05-17 |website=Flutter |language=en}}</ref>
Line 118:
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, an open-source Dart framework for building backend systems from [[Very Good Ventures]].<ref>{{Cite web |title=Dart Frog |url=https://dartfrogthenewstack.vgv.devio/ |accessdart-date=2023frog-05a-frontend-13 |website=dartfrog.vgv.dev |language=en}}</ref> an open-source moves-to-the-backend/|title=Dart frameworkFrog: forA buildingFrontend backendLanguage systemsMoves fromto [[Verythe GoodBackend|first=Loraine|last=Lawson|date=March Ventures]].2, 2023}}</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]].
Line 181:
 
== 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 ==
Line 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 224 ⟶ 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 (varint i = 1; i <= 10; i++) {
print(i);
}
}
</syntaxhighlight>
Line 242 ⟶ 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 263 ⟶ 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 instantiating 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);
}
</syntaxhighlight>
Line 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>
Line 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==