SlideShare a Scribd company logo
A BRIEF INTRODUCTION TO
DART
By Randal L. Schwartz <merlyn@stonehenge.com>
Version 1.3 on 10 July 2015
OVERVIEW
Not just a "smarter javascript"
TypeScript
CoffeeScript
ES6
Modern language
Native VM for
development
"node.js" server­side code
supporting #!/path/to/dart scripts
Transpiles efficiently to JavaScript
Great for single page applications
Runs in all modern browsers
DART...
is easy to learn
compiles to JavaScript
runs in the client and on the server
has great tools
supports types, without requiring them
scales from small scripts to large
has a wide array of built­in libraries
supports safe, simple concurrency with isolates
supports code sharing
is open source
HISTORY
Founded by Lars Bak and Kasper Lund of Google
Unveiled in October 2011
Dart 1.0 released November 2013
Approved as ECMA­408 standard in July 2014
Dart 1.6 (deferred loading) released August 2014
Dart running on Google Cloud in November 2014
"Dart VM in every browser" replaced with "better
JS" in March 2015
Dart 1.9 (enum and async) released March 2015
On­the­fly code analysis tools released March 2015
Dartpad announced May 2015
First dart developer summit in April 2015
Third edition of the spec published June 2015
Dartpad!
EDITORS
Webstorm (no cost to approved students,
classrooms, and open source projects)
IntelliJ Community Edition (open source)
Sublime Text (proprietary)
Dartpad (zero install!)
Eclipse (open source)
Or... it's just text... use your favorite editor!
But then you miss out on the code analyzer
tools...
HELLO, WORLD!
Of course... the first code...
Let's introduce a variable...
That's an untyped variable... let's ensure it's a
string...
main() {
print("Hello, world!");
}
main() {
var msg = "Hello, world!";
print(msg);
}
main() {
String person = "World";
print("Hello, $person!");
}
HELLO, PEOPLE!
Let's take it from the command line...
And refactor that into a subroutine...
main(List<String> args) {
String person = "World";
if (args.length > 0) {
person = args[0];
}
print("Hello, $person!");
}
main(List<String> args) {
String person = "World";
if (args.length > 0) {
person = args[0];
}
sayHelloTo(person);
}
sayHelloTo(String aPerson) {
print("Hello, $aPerson!");
}
IMPORTANT CONCEPTS
Everything is an object (inheriting from Object
class)
Typing is optional, but provides hints to the tools
Typing also provides guidance in "checked" mode
Code is completely compiled before execution
Includes top­level, local, and anonymous
functions, as well as class and instance methods
Privacy is two level: public and private (underscore
prefix)
BUILT­IN TYPES
Numbers (int and double)
String (String, UTF­16 internally)
Booleans (type bool, only values are true and false)
List (indexed starting at 0)
Maps (indexed by objects... yes objects)
Symbol (string that is identical if it is equal)
NUMBERS
Infinite precision ints in VM, normal range in
JavaScript
Doubles are classic IEEE 754 standard
Converting between strings and numbers:
int a = 3;
int header_constant = 0xBABE;
int large = 31415926535897932384626433832795;
double pi_like = large / 1e31;
main () => print(pi_like);
int three = int.parse("3");
double pi_kinda = double.parse("3.14");
String six_string = 6.toString();
String pi_sorta = pi_kinda.toString();
main () => print(pi_sorta);
BOOLEANS
Only two literals: true and false
Only true is true. Everything else is false
... unless you're in JavaScript, then it's normal JS
rules
When developing, you can ensure proper
operation before deploying
If you debug in checked mode, booleans must be
true or false
LISTS
Also known as arrays or ordered collections
Zero­based indexing (first element is item 0)
In checked mode (during development), can be
optionally typed:
Includes rich set of methods: add, addAll,
indexOf, removeAt, clear, sort and many
more
main () {
var meats = ['cow', 'pig', 'chicken'];
print(meats);
print(meats[0]);
meats.add('turkey');
print(meats[meats.length - 1]);
var only_numbers = <num> [3, 4, 5];
only_numbers.add('duck'); // fails in checked mode
}
MAPS
Maps have keys and values, both objects
Maps are created with a literal syntax or new Map
Typing information can be added for keys and
values:
main() {
var randal = {
'name': 'Randal L. Schwartz',
'address': '123 Main Street',
'city': 'Portland, Oregon',
};
print(randal['city']);
randal['city'] = 'Beaverton, Oregon';
randal['zip'] = 97001;
}
main() {
var randal = <String,String> {
...
FUNCTIONS
Types are optional, but are checked if present and
assist IDE:
Args can be positional, or named:
void sayMyName (String myName) {
print("My name is $myName.");
}
sayMyNameToo (myName) => print("My name is $myName.");
main () => sayMyName("Randal");
void sayMyName({String first, String last}) {
if (last != null) {
print("My name is $first $last");
} else {
print("My name is $first");
}
}
main () {
sayMyName(first: "Randal");
sayMyName(first: "Randal", last: "Schwartz");
}
OPTIONAL ARGS
Required args listed first, followed by optional args
Optional args can be positional or named, but not
both
Optional args can have defaults, or return null
otherwise:
void sayMyName(String first, [String last]) {
if (last != null) {
print("My name is $first $last");
} else {
print("My name is $first");
}
}
void sayMyNameToo(String first, [String last = "Smith"]) {
print("My name is $first $last");
}
main () {
sayMyName("Randal", "Schwartz");
sayMyNameToo("Randal");
}
OPERATORS
Rich set of operators similar to most modern
languages
15 levels of precedence, with normal usage of
parentheses to override
Integer divide: ~/
Pre and post increment and decrement
Type testing and casting: is, is! and as
Compound assignment: a += 3
Bitwise operators, like & and <<
Expression if/then/else:
var $this = 3 > 4 ? "was true" : "was false";
main () => print($this);
CONTROL FLOW
Generally very similar to C or JavaScript
if and else
for loops
while and do-while loops
switch and case
assert (throw exception if false in checked mode)
EXCEPTIONS
Unlike Java, no need to declare types you will
throw or catch
Exceptions typically subclass from Error or
Exception
But you can throw any object (which is everything)
Standard try, catch, finally sequence
CLASSES
Everything is an instance of a class, ultimately
inheriting from Object
Single inheritance with mixins
The new keyword can be used with a classname or
a class method
Objects have members consisting of methods and
instance variables
Classes can be abstract, typically defining a mixin
interface
Many operators can be overridden to provide a
custom interface
Extend a class with the extends keyword
CLASS MEMBERS
The dot is used to refer to both methods and
instance variables:
Getters and setters can be defined for instance
variables, allowing transparent migration
Class variables and methods also supported
class Point {
num x;
num y;
String toString() => "Point [$x,$y]";
}
main() {
var point = new Point();
point.x = 4;
point.y = 7;
print(point);
}
GENERICS
Optional types, so why use generics?
Inform the compiler during checked mode, and
the IDE during development:
Can also be used for interfaces:
main() {
var names = new List<String>();
names.addAll(['Randal', 'Kermit']);
names.add(1e20); // fails because 1e20 is not a String
}
abstract class Cache<T> {
T operator [] (String key);
operator []= (String key, T value);
}
ASYNCHRONOUS OPERATIONS
Similar to promise libraries in JavaScript
Provides Future (one value soon) and Stream
(many values over time) interfaces
Can use try/catch/finally­style logic with either of
these
For simple cases, async can be made to appear
non­async:
checkVersion() async {
var version = await lookUpVersion();
if (version == expectedVersion) {
// Do something.
} else {
// Do something else.
}
}
LIBRARIES
dart:core ­ numbers, collections,
strings, and more
dart:async ­ asyncronous
programming
dart:math ­ math and random
dart:html ­ browser­based apps
dart:io ­ I/O for command­line
apps
dart:convert ­ decoding and
encoding JSON, UTF­8, and more
dart:mirrors ­ reflection
... and many more standard
libraries
but wait... there's even more...
PUB
Like Perl's CPAN for Dart
Publish shared libraries
Incorporate those libraries into
your project
The pubspec.yaml controls
acceptable version numbers
Other users can view your
dependencies when they pull down
your pubspec.yaml
REFERENCES
Many parts of this talk inspired by
these sources:
Almost everything is linked from
Dart wikipedia page
Dart: Up and running
Dart news
dartlang.org

More Related Content

PDF
Modern Perl for Non-Perl Programmers
PDF
IO Streams, Files and Directories
PDF
What is Python Lambda Function? Python Tutorial | Edureka
PPT
Php
ZIP
Oral presentation v2
PPT
Bioinformatica 29-09-2011-p1-introduction
Modern Perl for Non-Perl Programmers
IO Streams, Files and Directories
What is Python Lambda Function? Python Tutorial | Edureka
Php
Oral presentation v2
Bioinformatica 29-09-2011-p1-introduction

Viewers also liked (20)

ODP
Visibilidad en Internet - Espacio Desarrolla
PDF
Cdi primaria mates 2012
DOCX
Examen presencial
PDF
Zfs administration
PDF
Open Day Corso di Preparazione al Test di Medicina 2012-13
PPTX
Estudio de la inversion
PDF
Raúl Fuentes (2)
PPTX
Big Data Analytics with Pentaho BI Server
DOC
Verd Fort6
PDF
Cdi primaria lengua_2009
PPTX
Slideshare presentacion
PPTX
OURs都市改革組織 2016年度工作成果報告
PDF
GardieTHESIS FINAL201610
DOCX
Handout 1 - CE, CG & CSR
PDF
PDF
Ceo Guide To Social Media
PPT
Ac Government 091005124359 Phpapp02 091007124148 Phpapp01 091009124527 Phpapp...
DOC
Ofimatica y procesadores de texto
PPS
Tình thương làm thăng hoa cuộc sống
PPT
Kareena kapoor wallpapers
Visibilidad en Internet - Espacio Desarrolla
Cdi primaria mates 2012
Examen presencial
Zfs administration
Open Day Corso di Preparazione al Test di Medicina 2012-13
Estudio de la inversion
Raúl Fuentes (2)
Big Data Analytics with Pentaho BI Server
Verd Fort6
Cdi primaria lengua_2009
Slideshare presentacion
OURs都市改革組織 2016年度工作成果報告
GardieTHESIS FINAL201610
Handout 1 - CE, CG & CSR
Ceo Guide To Social Media
Ac Government 091005124359 Phpapp02 091007124148 Phpapp01 091009124527 Phpapp...
Ofimatica y procesadores de texto
Tình thương làm thăng hoa cuộc sống
Kareena kapoor wallpapers
Ad

Similar to A brief introduction to dart (20)

PDF
Dart workshop
PPTX
Dart programming language
PDF
Discover Dart - Meetup 15/02/2017
PDF
Discover Dart(lang) - Meetup 07/12/2016
PDF
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
PPTX
Dart 1 In Dart, a programming language developed by Google, data types are us...
PPTX
Dart ppt
PPTX
App_development55555555555555555555.pptx
PPTX
pembelajaran tentang dart dalam bahasa inggris
PDF
Structured Apps with Google Dart
PPTX
Dart Programming.pptx
PDF
Flutter Festival IIT Goa: Session 1
PDF
Introduction to Dart
PPTX
1-introduction-to-dart-programming.pptx
PDF
1.-Introduction-to-Dart.pdf
PPTX
Chapter 2 Flutter Basics Lecture 1.pptx
PDF
Dart By Example 1st Edition Davy Mitchell
PPTX
Dart the Better JavaScript
Dart workshop
Dart programming language
Discover Dart - Meetup 15/02/2017
Discover Dart(lang) - Meetup 07/12/2016
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
Dart 1 In Dart, a programming language developed by Google, data types are us...
Dart ppt
App_development55555555555555555555.pptx
pembelajaran tentang dart dalam bahasa inggris
Structured Apps with Google Dart
Dart Programming.pptx
Flutter Festival IIT Goa: Session 1
Introduction to Dart
1-introduction-to-dart-programming.pptx
1.-Introduction-to-Dart.pdf
Chapter 2 Flutter Basics Lecture 1.pptx
Dart By Example 1st Edition Davy Mitchell
Dart the Better JavaScript
Ad

More from Randal Schwartz (10)

PDF
Why Flutter.pdf
PDF
Native mobile application development with Flutter (Dart)
PDF
Git: a brief introduction
PDF
Perl best practices v4
PDF
My half life with perl
PDF
Intro to git (one hour version)
PDF
Testing scripts
PDF
Introduction to git
ZIP
Introduction to Git
ZIP
Forget The ORM!
Why Flutter.pdf
Native mobile application development with Flutter (Dart)
Git: a brief introduction
Perl best practices v4
My half life with perl
Intro to git (one hour version)
Testing scripts
Introduction to git
Introduction to Git
Forget The ORM!

Recently uploaded (20)

PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
newyork.pptxirantrafgshenepalchinachinane
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
Digital Literacy And Online Safety on internet
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
Exploring VPS Hosting Trends for SMBs in 2025
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
Design_with_Watersergyerge45hrbgre4top (1).ppt
Tenda Login Guide: Access Your Router in 5 Easy Steps
newyork.pptxirantrafgshenepalchinachinane
Introuction about WHO-FIC in ICD-10.pptx
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Digital Literacy And Online Safety on internet
An introduction to the IFRS (ISSB) Stndards.pdf
Introuction about ICD -10 and ICD-11 PPT.pptx
Exploring VPS Hosting Trends for SMBs in 2025
Power Point - Lesson 3_2.pptx grad school presentation
SAP Ariba Sourcing PPT for learning material
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Paper PDF World Game (s) Great Redesign.pdf
SASE Traffic Flow - ZTNA Connector-1.pdf
Sims 4 Historia para lo sims 4 para jugar
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Decoding a Decade: 10 Years of Applied CTI Discipline
Module 1 - Cyber Law and Ethics 101.pptx
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt

A brief introduction to dart