Hitting the bullseye with Dart

dart-on-board

This year’s Google I/O introduced to me the Flutter SDK – Google’s mobile app SDK for creating iOS and Android Apps with one language – Dart. With Flutter’s Release Preview being announced I’ve started learning Dart in order to use Flutter and I’ve found it very easy to pick up.  I’ll cover an introduction to Dart in this article.

There are four high-level things to know about Dart:

  1. Object Oriented
    Look to work with classes and instances in a built-in manner.
  2. Statically Typed
    The compiler will infer and check types. These types can not be changed (not dynamic) and if you are coming from a dynamically typed language the association of the type with the variable and not the value may seem restrictive.
  3. C Style Syntax
    Dart looks like every other C style language and is familiar. This makes it easy to pick-up if you are familiar with C style languages. If not then its a good place to pick up the syntax style.
  4. Multiple Run-time Environment
    There are three ways to work with Dart output:
    A. It transpiles to JavaScript which gives away its web origins but also allows some cool web-based editors to start like the DartPad.
    B. There is a Dart VM where Dart can run on which gives Dart some legs for server-side execution.
    C. And finally as a mobile developer Dart compiles to binary ARM code so that we can produce native apk and ipa files.

Type Rules
Since Dart is statically typed knowing these types is important as well as knowing the following rules:

  1. Every value has a type.
  2. Every variable has a type it can reference.
  3. Once a variable has a type – it can not change.
  4. You need not annotate every type – Dart can infer the type.

Types
Some types to know which are very familiar are:

  1. String – ‘hello’
  2. int – 123
  3. double – 123.45
  4. dynamic – the catch all

Dynamic is an interesting one as it breaks the strict type checking allowing a wildcard type (think Any in Swift or id in Objective-C) that can be any of the others.

In the next article I’ll examine Object Oriented Dart.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s