Dart (programming language): Difference between revisions

Content deleted Content added
DartPad: image added
 
(3 intermediate revisions by 3 users not shown)
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|url=https://dart.dev/language/class-modifiers/|title=Class modifiers|website=dart.dev}}</ref>
Line 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 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 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 320 ⟶ 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 339 ⟶ 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==