Introduction To Dart

Dart is a client-optimized programming language for developing fast apps on various platform. The main goal is to offer the most productive programming language for multi-platform development, paired with a flexible execution runtime platform for app frameworks.

Overview

  • Dart is designed for a technical envelope that is particularly suited to client development, prioritizing both development and high-quality production experiences across a wide variety of compilation targets like web, mobile, and desktop.

  • Dart also forms the foundation of Flutter which is used for developing applications.

  • Dart provides the language and runtimes that boost Flutter apps, but Dart also supports many core developer tasks like formatting, analyzing, testing code, etc.

  • The Dart language is type safe i.e. it uses static type checking to ensure that a variable’s value always matches the variable’s static type.

  • Sometimes, this is referred to as sound typing. Although types are mandatory, type annotations are optional because of type inference.

  • The Dart typing system is also flexible, allowing the use of a dynamic type combined with runtime checks, which can be useful during experimentation or for code that needs to be especially dynamic.

  • Dart offers sound null safety, meaning that values can’t be null unless the programmer say they can be. With sound null safety, Dart can protect the programmer from null exceptions at runtime through static code analysis.

  • Unlike many other null-safe languages, when Dart determines that a variable is non-nullable, that variable is always non-nullable.

  • If you inspect the running code in the debugger, you’ll see that non-nullability is retained at runtime hence called as sound null safe.

History

  • Dart was revealed for the first time in the GOTO conference in the month of 10th - 12th October 2011 at Aarhus, Denmark. It is initially designed by the Lars bark and Kespar and developed by Google.

  • The first version 1.0 of Dart was released on November 14th, 2013, intended as a replacement of JavaScript.

  • In July 2014, the first edition of Dart language was approved by Ecma International approved at its 107th General Assembly.

  • The first version was criticized due to a malfunction on the web and this plan was dropped in 2015 with the 1.9 release of Dart.

  • The second version of Dart 2.0 was released in August, including a sound type system.

  • The recent version Dart 2.7 is supplemented with the extension method, which enables us to add any type of functionality.

Features of Dart

  • Dart is a platform-independent language and supports all operating systems such as Windows, Mac, Linux, etc.

  • It is an open-source language, which means it available free for everyone. It comes with a BSD license and recognized by the ECMA standard.

  • It is an object-oriented programming language and supports all features of oops such as inheritance, interfaces, and optional type features.

  • Dart is very useful in building real-time applications because of its stability.

  • Dart comes with the dar2js compiler which transmits the Dart code into JavaScript code that runs on all modern web browser.

  • The stand-alone Dart VM permits Dart code to run in a command-line interface environment.

Comparing Features of Dart and JavaScript

FeatureDartJavaScript
Type systemOptional, dynamic Weak,dynamic
ClassesYes, single inheritancePrototypical
InterfacesYes, multiple interfacesNo
ConcurrencyYes, with isolatesYes, with HTML5 web workers

Key Points to Remember

Before learning Dart, one should keep the following concepts in mind.

  • Everything in Dart is treated as an object including, numbers, Boolean, function, etc. like Python. All objects inherit from the Object class.

  • Dart tools can report two types of problems while coding, warnings and errors. Warnings are the indication that your code may have some problem, but it doesn’t interrupt the code’s execution, whereas error can prevent the execution of code.

  • Dart supports sound typing. We will learn about this in the next tutorial.

  • Dart supports generic types, like List(a list of integers) or List (a list of objects of any type).

Dart Platforms

Dart’s compiler technology lets you run code in different ways:

Date Native platform

For apps targeting mobile and desktop devices, Dart includes both a Dart VM with just-in-time (JIT) compilation and an ahead-of-time (AOT) compiler for producing machine code.

Web platform

For apps targeting the web, Dart can compile for development or production purposes. Its web compiler translates Dart into JavaScript.

Dart Native (machine code JIT and AOT)

  • During development, a fast developer cycle is critical for iteration. The Dart VM offers a just-in-time compiler (JIT) with incremental recompilation i.e. enabling hot reload, live metrics collections i.e. powering DevTools, and rich debugging support.

  • When apps are ready to be deployed to production—whether you’re publishing to an app store or deploying to a production backend—the Dart ahead-of-time (AOT) compiler can compile to native ARM or x64 machine code.

  • The AOT-compiled app launches with consistent, short startup time.

  • AOT (Ahead of Time) - It converts the Dart code in the optimized JavaScript code with the help of the dar2js compiler and runs on all modern web-browser. It compiles the code at build time.

  • JOT (Just-In-Time) - It converts the byte code in the machine code (native code), but only code that is necessary.

  • The AOT-compiled code runs inside an efficient Dart runtime that enforces the sound Dart type system and manages memory using fast object allocation and a generational garbage collector.

Dart Web (JavaScript dev & prod)

Dart Web enables running Dart code on web platforms powered by JavaScript. With Dart Web, compile Dart code to JavaScript code, which in turn runs in a browser—for example, V8 inside Chrome.

Dart web contains two compiliation modes:

  • An incremental development compiler enabling a fast developer cycle

  • An optimizing production compiler which compiles Dart code to fast, compact, deployable JavaScript. These effeciencies come from techniques such as dead-code elimination.