#Dart

The Dart Programming Language

A Dart programming language introduction to get up and running with dart and Flutter.

· 5 min read
The Dart Programming Language
Photo by Ricardo Arce / Unsplash

Dart is a general purpose, open source, object-oriented, type-safe programming language with C-Style syntax created by google in 2011. It is used to create frontend UIs for online and mobile applications. It's influenced by other programming languages such as Java, C# and Javascript. Dart is a client-optimized programming language, where its main purpose is to be used on cross-platform application development using the flutter framework.  

Ok, so in order to understand this definition, we need to break it down by its components. Some of it might me obvious, but for the fun of it, I'll add a basic summery of the definitions and links to Wikipedia articles to whomever might need it.

  • Object-Oriented: "It's a programming paradigm based on the concept of object".
  • Type-Safe: "Type safety and type soundness are the extent to which a programming language discourages or prevents type errors". In other words, only the operations that can be performed on data in the language, are those allowed by type of data.

Great! let us go deeper on type soundness, as Dart is and has a static type check and runtime check. The first one is used in compilation on the deployment/production phase while the latter is used for the development phase and fast prototyping. Dart also has a dynamic type, where type check ups are run at runtime. Dart also uses type inference, where the type of a variable is defined by its value on its creation.

Sound null safety

In Dart, values cannot be null unless it is specified to be null, data can be nullable or not, but not both. If a variable in dart is set to be non-nullable, that variable will always be non-nullable.

The Compiler

Dart uses a compiler to compile source code to machine code that can be run on an architecture or the dart virtual machine. We will focus on the Dart VM later on, but for now we will list the following architecture where dart can be run.

Architecture Description
ARM 32 JIT or AOT
ARM 64 JIT or AOT
X86_64 JIT or AOT
Web (Javascript) dartdevc or dart2js

Where the following definitions are in order:

  • JIT: Stands for Just In Time compilation.
  • AOT: Stands for Ahead Of Time compilation.
  • dart2js: Is the dart to javascript compiler.
  • dartdevc: Is the dart development compiler.

Dart phases

Ok, so you might be wondering, What's with all that different compilation stuff going on here? The answer is quite simple, Dart is trying to breach the gap between the developer experience and the customer experience by providing developers with tools such as just in time compilation and hot reloading while in production or deployment using ahead of time compilation.

Just think about it like this:

Development Phase Production phase
JIT AOT
Hot-Reloading Better performance
Happy developer Happy customer

Dart CLI

The dart CLI is the command line interface tool used for creating, compiling, migrating, installing dependencies and more. There are some common available commands and they are as follow:

Manage your Flutter app development.

Common commands:

  flutter create <output directory>
    Create a new Flutter project in the specified directory.

  flutter run [options]
    Run your Flutter application on an attached device or in an emulator.

Usage: flutter <command> [arguments]

Global options:
-h, --help                  Print this usage information.
-v, --verbose               Noisy logging, including all shell commands
                            executed.
                            If used with "--help", shows hidden options. If used
                            with "flutter doctor", shows additional diagnostic
                            information. (Use "-vv" to force verbose logging in
                            those cases.)
-d, --device-id             Target device id or name (prefixes allowed).
    --version               Reports the version of this tool.
    --suppress-analytics    Suppress analytics reporting when this command runs.

Available commands:

Flutter SDK
  bash-completion   Output command line shell completion setup scripts.
  channel           List or switch Flutter channels.
  config            Configure Flutter settings.
  doctor            Show information about the installed tooling.
  downgrade         Downgrade Flutter to the last active version for the current
                    channel.
  precache          Populate the Flutter tool's cache of binary artifacts.
  upgrade           Upgrade your copy of Flutter.

Project
  analyze           Analyze the project's Dart code.
  assemble          Assemble and build Flutter resources.
  build             Build an executable app or install bundle.
  clean             Delete the build/ and .dart_tool/ directories.
  create            Create a new Flutter project.
  drive             Run integration tests for the project on an attached device
                    or emulator.
  gen-l10n          Generate localizations for the current project.
  pub               Commands for managing Flutter packages.
  run               Run your Flutter app on an attached device.
  test              Run Flutter unit tests for the current project.

Tools & Devices
  attach            Attach to a running app.
  custom-devices    List, reset, add and delete custom devices.
  devices           List all connected devices.
  emulators         List, launch and create emulators.
  install           Install a Flutter app on an attached device.
  logs              Show log output for running Flutter apps.
  screenshot        Take a screenshot from a connected device.
  symbolize         Symbolize a stack trace from an AOT-compiled Flutter app.

Run "flutter help <command>" for more information about a command.
Run "flutter help -v" for verbose help output, including less commonly used
options.

Dart VM

The Dart VM is not a virtual machine like the Java Virtual Machine, in a way, it is all the components that provides an execution environment for a high-level programming language. So too much can be said for the VM but to keep things simple, we can say that the Dart VM includes the following:

  • The runtime system.
  • The development components such as:
    • debugging tools.
    • hot-reloading.
    • etc.
  • JIT compilation pipeline.
  • AOT compilation pipeline.

The heap memory uses a garbage collector to reclaim memory allocated but no longer used. The Dart VM can execute the code in 2 ways from source through JIT or AOT and from snapshots which includes JIT, AOT or kernel snapshots.


Thank you for reading my post, this should be enough information for us to start our journey with the Dart and Flutter ecosystem. I hope you find this information useful and sparks the fire to get you started with Dart and flutter. The next series of post will be more in depth and with a more hands-on approach.

Cheers! 🍻

Resources

Dart overview
A short introduction to Dart
Dart programming language
Dart is a client-optimized language for fast apps on any platform
DartPad
An online Dart editor with support for console, web, and Flutter apps.

Related Articles

Flutter vs Javascript

Flutter vs Javascript

· 2 min read
Dart Fundamentals I

Dart Fundamentals I

· 9 min read