A Beginners Guide to Dart - Types, Functions, Variables and Objects - Part One
What Will I Learn?
- You will learn about the Basics of programming
- You will learn about Objects in Dart
- You will learn about Types in Dart
- You will learn about how Functions are Objects in Dart
- You will learn how to use closures and first class functions
- You will learn how to bind variables in Dart
OS Support for Dart:
- The Dart SDK
- A dart supported text editor
- A little time to sit and watch a video and some patience to learn the language
Resources for Dart:
- Dart Website: https://www.dartlang.org/
- Dart Official Documentation: https://www.dartlang.org/guides/language/language-tour
- Dart GitHub repository: https://github.com/dart-lang/sdk
- Awesome Dart GitHub Repository: https://github.com/yissachar/awesome-dart
- Pub website: https://pub.dartlang.org
Dart Logo (Google): https://www.dartlang.org/
Types in the Dart Programming Language
Dart is general purpose programming language that was originally designed by Google for client side development. The language is both Imperative and Object Oriented with some small functional features scattered throughout. With an Imperative language, a developer defines sequential instructions that build a program. This is further abstracted upon with the Object system in Dart. Every Type that can be assigned to a variable is an Object in Dart.
Dart contains seven main primitive types in its static type system: numbers, strings, booleans, lists, maps, runes and symbols. Numbers include Floats and Integers. Strings are used to represent text by using single and double quotations. Booleans are binary values that can either be True or False. Lists are zero indexable collections of data. Maps are collections with associative key-value pairs. Runes are UTF-32 code points which are used to create strings and characters. Symbols are symbolic names used for mirrors, invocations, and functions.
First Class Functions and Closures
A side effect of most types being Objects is that functions are also Objects in Dart. Functions are first class citizens in Dart because they also support all operations that are available to Objects. They can be assigned to a variable, passed as an argument to another function, returned from a function, stored in other Data collections, and created in any scope. Functions can have static type signatures and they can have dynamic type signatures. Functions can also be anonymous or in other terms, closures.
In the above image, there are examples of the traits mentioned above. Two functions
sub are defined using single line notation. The
choose function returns either
sub depending on the boolean argument that is passed into it. The
exec function takes in a function as an argument and that function can be any function that takes in two arguments. The
operator list contains both the
sub functions inside of it.
The Source Code for this video may be found here: https://github.com/tensor-programming/dart_for_beginners