Dart (programming language)

Dart is a general-purpose programming language originally developed by Google and later approved as a standard by Ecma (ECMA-408).[7] It is used to build web, server, desktop, and mobile applications.[8]

Dart is an object-oriented, class defined, garbage-collected language[9] using a C-style syntax that transcompiles optionally into JavaScript. It supports interfaces, mixins, abstract classes, reified generics, static typing, and a sound type system.[10]

Dart
Dart programming language logo
ParadigmMulti-paradigm: scripting, object-oriented (class-based), imperative, reflective, functional, garbage-collected[1]
Designed byLars Bak and Kasper Lund
DeveloperGoogle
First appearedOctober 10, 2011[2]
Stable release
2.2.0 / February 26, 2019[3]
Preview release
2.2.0-dev.2.0 / February 14, 2019[4]
Typing discipline1.x: Optional, 2.x: Static[5]
PlatformCross-platform
OSCross-platform
LicenseBSD
Filename extensions.dart
Websitewww.dartlang.org
Major implementations
Dart VM, dart2js, DDC, Flutter
Influenced by
C#, Erlang, JavaScript, Smalltalk, Strongtalk[6]

History

Dart was unveiled at the GOTO conference in Aarhus, Denmark, October 10–12, 2011.[11] The project was founded by Lars Bak and Kasper Lund.[12] Dart 1.0 was released on November 14th, 2013.[13] In August 2018, Dart 2.0 was released, with language changes including a sound type system.[14]

Standardization

Ecma International has formed technical committee TC52[15] to work on standardizing Dart, and inasmuch as Dart can be compiled to standard JavaScript, it works effectively in any modern browser. Ecma International approved the Dart language specification first edition in July 2014, at its 107th General Assembly,[16] and a second edition in December 2014.[17] The latest specification is available at https://www.dartlang.org/guides/language/spec.

Usage

There are three main ways to run Dart code:

Compiled as JavaScript
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."[18] When running Dart code in a web browser the code is precompiled into JavaScript using the dart2js compiler. Compiled as JavaScript, Dart code is compatible with all major browsers with no need for browsers to adopt Dart. Through optimizing the compiled JavaScript output to avoid expensive checks and operations, code written in Dart can, in some cases, run faster than equivalent code hand-written using JavaScript idioms.[19]
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 Dart SDK are written mostly in Dart, the stand-alone Dart VM is a critical part of the SDK. 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.[20]
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.[21]

Isolates

To achieve concurrency, Dart uses isolates, which are independent workers that do not share memory, but instead use message passing. This is similar to Erlang actors. 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.[22]

Snapshots

Snapshots are a core part of the Dart VM. Snapshots are files which store objects and other runtime data.

Script snapshots
Dart programs can be compiled into snapshot files. These files contain all of the program code and dependencies preparsed and ready to execute. This allows fast startups.
Full snapshots
The Dart core libraries can be compiled into a snapshot file which allows fast loading of the libraries. Most standard distributions of the main Dart VM have a prebuilt snapshot for the core libraries which is loaded at runtime.
Object snapshots
Dart is a very asynchronous language. With this, it uses isolates for concurrency. Since these are workers which pass messages, it needs a way to serialize a message. This is done using a snapshot, which is generated from a given object, and then this is transferred to another isolate for deserializing.

Native mobile apps

Google has introduced Flutter for native mobile app development on both Android and iOS.[23] 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. Flutter works with Firebase 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.[24]

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,[25] stating that it now runs faster than handwritten JavaScript on Chrome's V8 JavaScript engine for the DeltaBlue benchmark.[26]

Editors

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

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

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

In June 2015, Google transferred the CDE project to GitHub as a free software project and ceased active investment in CDE.[35]

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

SIMD

In 2013, John McCutchan announced[37] that he had created a performant interface to single instruction, multiple data (SIMD) instruction sets for Dart.

The interface consists of two types:

  • Float32×4, 4× single precision floating point values
  • Uint32×4, 4× 32-bit unsigned integer values

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:

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;
// this is a fibonacci function implementation with a ternary operator in Dart
// this code shall be read as:
// If int n > 2, return fib(n - 1) + fib(n - 2); 
// otherwise, return int 1 as result

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

A simple class:

// Import the math library to get access to the sqrt function.
import 'dart:math' as math;

// Create a class for Point.
class Point {

  // Final variables cannot be changed once they are assigned.
  // Create 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 Operator Overloading
  Point operator +(Point other) => Point(x + other.x, y + other.y);
  // When you 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 p1 = Point(10, 10);
  var p2 = Point.origin();
  var distance = p1.distanceTo(p2);
  print(distance);
}

Influences from other languages

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

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

Criticism

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 to focus instead on compiling Dart to JavaScript.[42]

See also

References

  1. ^ Kopec, David. Dart for Absolute Beginners. p. 56. ISBN 9781430264828. Retrieved 24 November 2015.
  2. ^ Bak, Lars. "Dart: a language for structured web programming". Google Code Blog. Google. Retrieved 31 January 2016.
  3. ^ https://github.com/dart-lang/sdk/releases
  4. ^ https://github.com/dart-lang/sdk/releases
  5. ^ https://www.dartlang.org/faq#q-is-dart-a-statically-typed-language
  6. ^ "Web Languages and VMs: Fast Code is Always in Fashion. (V8, Dart) - Google I/O 2013". Google. Retrieved 22 December 2013.
  7. ^ https://www.dartlang.org/
  8. ^ https://flutter.io
  9. ^ "A Tour of the Dart Language". www.dartlang.org. Retrieved 2018-08-09.
  10. ^ https://www.dartlang.org/guides/language/sound-dart
  11. ^ "Dart, a new programming language for structured web programming", GOTO conference (presentation) (opening keynote), Århus conference, 2011-10-10
  12. ^ Ladd, Seth. "What is Dart". What is Dart?. O'Reilly. Retrieved August 16, 2014.
  13. ^ "Dart 1.0: A stable SDK for structured web apps". news.dartlang.org. Retrieved 2018-08-08.
  14. ^ Moore, Kevin (2018-08-07). "Announcing Dart 2 Stable and the Dart Web Platform". Dart. Retrieved 2018-08-08.
  15. ^ "TC52 - Dart". Retrieved 2013-12-16.
  16. ^ Anders Thorhauge Sandholm. "Dart News & Updates". dartlang.org.
  17. ^ Anders Thorhauge Sandholm. "Dart News & Updates". dartlang.org.
  18. ^ "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.
  19. ^ "JavaScript as a compilation target: Making it fast" (PDF). Dartlang.org. Archived from the original (PDF) on 2016-07-02. Retrieved 2013-08-18.
  20. ^ "An Introduction to the dart:io Library". Dartlang.org. Retrieved 2013-07-21.
  21. ^ "Flutter FAQ". flutter.io. How does Flutter run my code on iOS?. Retrieved 2016-10-02.
  22. ^ Moore, Kevin (February 23, 2018). "Dart2 Breaking Change: Removing web support for dart:mirrors and dart:isolate". Google Groups.
  23. ^ Flutter
  24. ^ https://webdev.dartlang.org/angular/guide/deployment
  25. ^ Ladd, Seth (2013-03-28). "Dart News & Updates: Why dart2js produces faster JavaScript code from Dart". News.dartlang.org. Retrieved 2013-07-21.
  26. ^ "Dart Performance". Dartlang.org. Retrieved 2013-07-21.
  27. ^ "Google Releases Dart Editor for Windows, Mac OS X, and Linux".
  28. ^ "Google Release Dart Eclipse Plugin".
  29. ^ Ladd, Seth (2015-04-30). "The present and future of editors and IDEs for Dart". Dart News & Updates. Google. Retrieved 2015-05-18.
  30. ^ "JetBrains Plugin Repository : Dart". Plugins.intellij.net. Retrieved 2013-07-21.
  31. ^ "Dart Tools". www.dartlang.org. Retrieved 2016-11-15.
  32. ^ Beaufort, François. "The chromium team is currently actively working".
  33. ^ "A Chrome app based development environment".
  34. ^ "Chrome Story: Spark, A Chrome App from Google is an IDE for Your Chromebook".
  35. ^ Saroop, Sri. "Chrome Dev Editor: Announcements".
  36. ^ Ladd, Seth (2015-05-06). "Announcing DartPad: A friction-free way to explore Dart code". Dart News & Updates. Google. Retrieved 2015-05-18.
  37. ^ "Bringing SIMD to the web via Dart" (PDF).
  38. ^ "Algol Family". c2.com.
  39. ^ Bracha, Gilad; Griswold, David (September 1996). "Extending the Smalltalk Language with Mixins" (PDF). OOPSLA Workshop. OOPSLA.
  40. ^ "The Essence of Google Dart: Building Applications, Snapshots, Isolates". InfoQ.
  41. ^ 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.
  42. ^ Seth Ladd. "Dart News & Updates". dartlang.org.

Bibliography

External links

Ceylon (programming language)

Ceylon is an object-oriented, strongly statically typed programming language with an emphasis on immutability, created by Red Hat. Ceylon programs run on the Java virtual machine (JVM), and can be compiled to JavaScript.

The language design focuses on source code readability, predictability, toolability, modularity, and metaprogrammability.Important features of Ceylon include:

A type system enforcing null safety and list element existence at compile time

Regular syntax and semantics, avoiding special cases and primitively-defined constructs in favor of syntactic sugar

Support for generic programming and metaprogramming, with reified generics

Modularity built into the language, based on JBoss modules, interoperable with OSGi and Maven

powerful tools, including an Eclipse-based IDEThe name "Ceylon" is an oblique reference to Java, in that Java and Sri Lanka, formerly known as Ceylon, are islands known for growth and export of coffee and tea.

In August 2017, Ceylon was donated to the Eclipse Foundation.

Covariance and contravariance (computer science)

Many programming language type systems support subtyping. Variance refers to how subtyping between more complex types relates to subtyping between their components. For instance, if the type Cat is a subtype of Animal, then an expression of type Cat can be used wherever an expression of type Animal is used. How should a list of Cats relate to a list of Animals? Or how should a function returning Cat relate to a function returning Animal? How should a list of Animals contain at the same time an instance of Cat and another of Fish? Depending on the variance of the type constructor, the subtyping relation of the simple types may be either preserved, reversed, or ignored for the respective complex types. In the OCaml programming language, for example, "list of Cat" is a subtype of "list of Animal" because the list constructor is covariant. This means that the subtyping relation of the simple types are preserved for the complex types. On the other hand, "function from Animal to String" is a subtype of "function from Cat to String" because the function type constructor is contravariant in the argument type. Here the subtyping relation of the simple types is reversed for the complex types.

A programming language designer will consider variance when devising typing rules for language features such as arrays, inheritance, and generic datatypes. By making type constructors covariant or contravariant instead of invariant, more programs will be accepted as well-typed. On the other hand, programmers often find contravariance unintuitive, and accurately tracking variance to avoid runtime type errors can lead to complex typing rules. In order to keep the type system simple and allow useful programs, a language may treat a type constructor as invariant even if it would be safe to consider it variant, or treat it as covariant even though that could violate type safety.

Dart

Dart or DART may refer to:

Dart (missile), a projectile weapon

Dart, the equipment in the game of darts

Dart (sewing), a fold sewn into the fabric of a garment

Ecma International

Ecma is a standards organization for information and communication systems. It acquired its current name in 1994, when the European Computer Manufacturers Association (ECMA) changed its name to reflect the organization's global reach and activities. As a consequence, the name is no longer considered an acronym and no longer uses full capitalization.

The organization was founded in 1961 to standardize computer systems in Europe. Membership is open to large and small companies worldwide that produce, market or develop computer or communication systems, and have interest and experience in the areas addressed by the group's technical bodies. It is located in Geneva.

Gilad Bracha

Gilad Bracha is the creator of the Newspeak programming language, a software engineer at Tensyr, and a former software engineer at Google where he worked on the Dart programming language team. He is a co-author of the second and third editions of the Java Language Specification, and a major contributor to the second edition of the Java Virtual Machine Specification.Between 1994 and 1997, he worked on the Smalltalk system developed by Animorphic Systems, a company that was bought by Sun in 1997. From 1997 to 2006, he worked at Sun Microsystems as Computational Theologist and, as of 2005, Distinguished Engineer, on various aspects of the specification and implementation of Java. Following that, he was Distinguished Engineer at Cadence Design Systems from 2006 to 2009, where he led a team of developers designing and implementing Newspeak.Bracha received his B.Sc in Mathematics and Computer Science from Ben Gurion University in Israel and his Ph.D. in Computer Science from the University of Utah.

Bracha won the Senior Dahl–Nygaard Prize in 2017.

Google Web Toolkit

Google Web Toolkit (GWT ), or GWT Web Toolkit, is an open-source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. Other than a few native libraries, everything is Java source that can be built on any supported platform with the included GWT Ant build files. It is licensed under the Apache License version 2.0.GWT emphasizes reusable approaches to common web development tasks, namely asynchronous remote procedure calls, history management, bookmarking, UI abstraction, internationalization, and cross-browser portability.

Haxe

Haxe is a high-level cross-platform multi-paradigm programming language and compiler that can produce applications and source code, for many different computing platforms, from one code-base. It is free and open-source software, distributed under the GNU General Public License (GPL) version 2, and the standard library under the MIT License.

Haxe includes a set of common functions that are supported across all platforms, such as numeric data types, text, arrays, binary and some common file formats. Haxe also includes platform-specific application programming interface (API) for Adobe Flash, C++, PHP and other languages. OpenFL, Kha, Heaps and Flambe are popular Haxe frameworks that enable creating multi-platform content from one codebase.Haxe originated with the idea of supporting client-side and server-side programming in one language, and simplifying the communication logic between them. Code written in the Haxe language can be source-to-source compiled into ActionScript 3, JavaScript, Java, C++, C#, PHP, Python, Lua and Node.js. Haxe can also directly compile SWF, HashLink and Neko bytecode.

Many popular IDEs and source code editors have support available for Haxe development. No particular development environment or tool set is officially recommended by the Haxe Foundation, although VS Code and IntelliJ IDEA have extensions to support Haxe development. The core functionalities of syntax highlighting, code completion, refactoring, debugging, etc., are available in various degree. The comparison of IDE choices for Haxe programmers has quite in-depth information.

To help leverage existing code, the Haxe community has created source code converters for ActionScript 3 to Haxe and C# to Haxe The Haxe compiler can also output Haxe into standalone ActionScript 3, C++, C#, Java, PHP, Python and Lua source code, which can then be pulled out of the Haxe ecosystem and developed with traditional workflows.

Major users of Haxe include BBC, Coca-Cola, Disney, Hasbro, Mattel, Nickelodeon, Prezi, TiVo, Toyota, and Zynga.

Index of JavaScript-related articles

This is a list of articles related to the JavaScript programming language.

Lars Bak (computer programmer)

Lars Bak is a Danish computer programmer. He is known as a JavaScript expert and for his work on virtual machines. He previously worked for Google, having contributed to the Chrome browser by developing the V8 JavaScript engine. After years abroad, Lars Bak now lives near Aarhus in Denmark. He is currently working on a new startup, building a new programming language for Internet of Things systems.

List of Ecma standards

This is a list of standards published by Ecma International, formerly the European Computer Manufacturers Association.

SIMD

Single instruction, multiple data (SIMD) is a class of parallel computers in Flynn's taxonomy. It describes computers with multiple processing elements that perform the same operation on multiple data points simultaneously. Such machines exploit data level parallelism, but not concurrency: there are simultaneous (parallel) computations, but only a single process (instruction) at a given moment. SIMD is particularly applicable to common tasks such as adjusting the contrast in a digital image or adjusting the volume of digital audio. Most modern CPU designs include SIMD instructions to improve the performance of multimedia use. SIMD is not to be confused with SIMT, which utilizes threads.

Overview
Advertising
Communication
Software
Platforms
Hardware
Development
tools
Publishing
Search
(timeline)
Events
People
Other
Related
Code analysis
Transcompilers
Concepts
Debuggers
Doc generators
Editors (comparison)
Engines
Frameworks
Related technologies
Package managers
Server-side
Unit testing
People

This page is based on a Wikipedia article written by authors (here).
Text is available under the CC BY-SA 3.0 license; additional terms may apply.
Images, videos and audio are available under their respective licenses.