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.
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.
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.
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.
The stand-alone Dart VM permits Dart code to run in a command-line interface environment.
|Type system||Optional, dynamic Weak,||dynamic|
|Classes||Yes, single inheritance||Prototypical|
|Interfaces||Yes, multiple interfaces||No|
|Concurrency||Yes, with isolates||Yes, 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’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.
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.
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 contains two compiliation modes:
An incremental development compiler enabling a fast developer cycle