A Beginners Guide to Dart - Control Flow and Low Level Compilation - Part Two

in #utopian-io6 years ago

dart-bird.jpg

Repository

https://github.com/dart-lang/sdk

What Will I Learn?

  • You will learn the difference between JIT and AOT compilation
  • You will learn about Control Flow Structures
  • You will learn why Types are important
  • You will learn how to make Loops
  • You will learn about Boolean Types and Boolean Algebra
  • You will learn about Conditions in Dart

Requirements

System Requirements:
OS Support for Dart:
  • Windows
  • macOS
  • Linux

Required Knowledge

  • 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:

Sources:

Dart Logo (Google): https://www.dartlang.org/

Difficulty

  • Beginner

Description

In this Dart video tutorial, we take a much lower level look at some of the topics that were covered in the last tutorial. We also go ahead and take a look at control flow structures like if, if/else, for and while. We look at conditionals and Boolean types and how they relate to the other control flow structures. We also talk about why Types are important and the implications of Dart being a static language. This includes talking about the dynamic and Object types.

Dart as a Statically Typed Language and its Relation to the Compiler

Up until the release of Dart 2.0, Dart was a dynamically typed programming language. This meant that when you compiled a Dart program, the types were checked at run-time rather then at compile type. This also meant that you didn't need to supply a type for a variable, function or object and the compiler would infer these things for you. When Dart used this method of type checking, it also relied heavily on its Just In Time (JIT) compiler. As Dart moved into Dart 2.0, the type system was shifted from Dynamic to Static. With static typing, the types are known at compile type rather then during run time. This not only boosts the performance of the language significantly, but it also makes the Ahead of Time (AOT) compiler work much better. Now when you compile a Dart program, the compiler can suggest fixes and give clearer errors to the user.

compiler-cycle.png

The image above shows the process by which you can interact with your computer through the Dart programming language. You write your Dart code and submit it to the compiler and virtual machine. The Virtual Machine produces machine readable byte-code so that the computer can follow the instructions from the code. This then produces an output based on what the program is. Then the user can take this output and change their program accordingly. Because Dart used to be dynamic, it contains both a JIT and AOT compiler and it also has types that act like dynamic types. These types are the Object type and the dynamic type. The dynamic type is a bit of a catch all type, if the compiler can't infer the type and the user doesn't supply one, then it is assumed to be dynamic. The Object type on the other hand is the type that all other types are derived from.

Using Control Flow Structures in Dart

In Dart, because the language is imperative we have access to many of the C-style control flow structures. This of course, includes structures like if, if/else, while, do/while, switch, and for. Each of these structures uses a set of logic to allow the program flow to change. Some allow for code re-use; such is the case for the looping structures and others allow the program to branch from one path to another. This not only makes it easy for the developer to control the flow of the program but it also helps keep the code easy to reason about.

conditionals.png

In the image above, we have some examples of if/else statements. Also at the bottom, there is a list of the conditionals that are included in the Dart programming language. The if/else structure allows the user to control the flow of the program based on a conditional statement which appears in the parenthesis. If the initial conditional evaluates to true, then the first block of code is executed. If the conditional evaluates to false, then the program skips over the first block of code and moves on to the next block. If another if statement follows the else keyword, the compiler checks the conditional statement and follows the same pattern as before.

The Source Code for this video may be found here: https://github.com/tensor-programming/dart_for_beginners/tree/tensor-programming-patch-1

Video Tutorial

Curriculum

Proof of Work Done

https://github.com/tensor-programming

Sort:  

Hi @tensor

Thank you again for another great video tutorial.

I like the way you write your post which truly supplement to the video tutorial.

Your thoughts are well organized and flows very well in the tutorial.

Thanks for doing such good work and I have used you as an example for others to follow as they create their video tutorials.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Thank you @rosatravels. Yes, I noticed that you had used this tutorial specifically as a reference. Feel free to reference any of my material in the future.

Thank you for your review, @rosatravels! Keep up the good work!

Hi @tensor!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @tensor!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Hi, @tensor!

You just got a 5.29% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Coin Marketplace

STEEM 0.22
TRX 0.20
JST 0.034
BTC 98923.04
ETH 3381.66
USDT 1.00
SBD 3.09