Introduction to Dart

42
#flydart #gdgac Welcome

description

Introductory Tech Talk on Dart. Presented at the GDG Aachen Dart Flight School. Based on the slides by Seth Ladd: http://goo.gl/EbY4uS

Transcript of Introduction to Dart

Page 1: Introduction to Dart

#flydart #gdgac

Welcome

Page 2: Introduction to Dart

#flydart #gdgac

Page 3: Introduction to Dart

#flydart #gdgac

Introduction to

Based on the Slides by Seth Ladd

Page 4: Introduction to Dart

#flydart #gdgac

Who am I?

Sebastian MauerGDG Aachen Co-Lead CS Student

Software Engineer I don’t work for Google …yet

aka

Page 5: Introduction to Dart

#flydart #gdgac

Page 6: Introduction to Dart

#flydart #gdgac

✔ Improved productivity ✔ Increased performance

is about two things:

Page 7: Introduction to Dart

#flydart #gdgac

Learn the language in under one hour.(we have the whole day)

Page 8: Introduction to Dart

#flydart #gdgac

Use the tools you already know

IntelliJ Sublime

Eclipse (DartEditor)

Page 9: Introduction to Dart

#flydart #gdgac

Compile to JavaScript(runs across the modern web)

Page 10: Introduction to Dart

#flydart #gdgac

Run Dart on the server with the Dart VM

Page 11: Introduction to Dart

#flydart #gdgac

require.js

Backbone

Backbone Marionette

jQuery

Modernizr

moment.js

dest templates

PhantomJS

JasmineDocs

Docs

Docs

Docs

Docs

Docs

Docs

Docs

Docs

Page 12: Introduction to Dart

#flydart #gdgac

Clear and consistent

Unit test

Dart SDK

Polymer

Intl

Pac

kag

es

Page 13: Introduction to Dart

#flydart #gdgac

Apps start small, but grow and scale

Page 14: Introduction to Dart

#flydart #gdgac

Simple syntax, ceremony freeclass Hug { Familiar

Page 15: Introduction to Dart

#flydart #gdgac

Simple syntax, ceremony freeclass Hug { num strength; Hug(this.strength); Terse

Page 16: Introduction to Dart

#flydart #gdgac

Simple syntax, ceremony freeclass Hug { num strength; Hug(this.strength); !Hug operator +(Hug other) { return new Hug(strength + other.strength); }

Operator overriding

Page 17: Introduction to Dart

#flydart #gdgac

Simple syntax, ceremony freeclass Hug { num strength; Hug(this.strength); !Hug operator +(Hug other) { return new Hug(strength + other.strength); } !void patBack({int hands: 1}) { // ... }

Named, optional params w/ default value

Page 18: Introduction to Dart

#flydart #gdgac

Simple syntax, ceremony free… Hug operator +(Hug other) { return new Hug(strength + other.strength); } !void patBack({int hands: 1}) { // ... } !String toString() => "Embraceometer reads $strength";

One-line Function

Page 19: Introduction to Dart

#flydart #gdgac

Simple syntax, ceremony free… Hug operator +(Hug other) { return new Hug(strength + other.strength); } !void patBack({int hands: 1}) { // ... } !String toString() => "Embraceometer reads $strength";

String interpolation

Page 20: Introduction to Dart

#flydart #gdgac

Page 21: Introduction to Dart

#flydart #gdgac

Page 22: Introduction to Dart

#flydart #gdgac

Clean semantics and behavior

• Only true is truthy

• There is no undefined, only null

• No type coercion with ==, +

Examples

Page 23: Introduction to Dart

#flydart #gdgac

Clean semantics and behavior

"hello".missing // ??

Class 'String' has no instance getter 'missing'NoSuchMethodError : method not found: ‚missing'Receiver: "hello"Arguments: []

LOGICAL!

Page 24: Introduction to Dart

#flydart #gdgac

Clean semantics and behavior

'hello' > 1 // ??Class 'String' has no instance method '>'.

LOGICAL!

Page 25: Introduction to Dart

#flydart #gdgac

Clean semantics and behavior

var foo = 'top-level'; !main() { if (true) { var foo = 'inside'; } ! print(foo); // ?? What will this print? }

LOGICAL!

Variable scope?

NO HOISTING!top-level

Page 26: Introduction to Dart

#flydart #gdgac

Clean semantics and behavior

class AwesomeButton { ! AwesomeButton(button) { button.onClick.listen((Event e) => this.atomicDinosaurRock()); } ! atomicDinosaurRock() { /* ... */ } }

LOGICAL!

Scope of „this“?

LEXICAL THIS!

Page 27: Introduction to Dart

#flydart #gdgac

Scalable Structure

Functions Classes

Libraries

Packages

Mixins Interfaces

library games; !import 'dart:math'; import 'players.dart'; !class Darts { // ... } !class Bowling { // ... } !Player findOpponent(int skillLevel) { // ... }

Page 28: Introduction to Dart

#flydart #gdgac

Too many Buttonsvar button = new ButtonElement(); button.id = 'fancy'; button.text = 'Click Point'; button.classes.add('important'); button.onClick.listen((e) => addTopHat()); !parentElement.children.add(button);

Page 29: Introduction to Dart

#flydart #gdgac

Method cascadesvar button = new ButtonElement() ..id = 'fancy' ..text = 'Click Point' ..classes.add('important') ..onClick.listen((e) => addTopHat()); !parentElement.children.add(button);

Page 30: Introduction to Dart

#flydart #gdgac

Inline initialization

parentElement.children.add( new ButtonElement()..text = 'Click Point');

Page 31: Introduction to Dart

#flydart #gdgac

One of these things is not like the other

Object

Persistable

Hug

Hug is not a is-a Persistable

Don’t pollute your inheritance tree!

Page 32: Introduction to Dart

#flydart #gdgac

Don’t inherit, mixin!

Object

Hug Mixin Persistable

Page 33: Introduction to Dart

#flydart #gdgac

Mixinsabstract class Persistable { save() { ... } load() { ... } toJson(); } !class Hug extends Object with Persistable { Map toJson() => {'strength':10}; } !main() { var embrace = new Hug(); embrace.save(); }

Extend object & no constructors? You can

be a mixin!

Apply the Mixin

Use Methods from the Mixin

Page 34: Introduction to Dart

#flydart #gdgac

Page 35: Introduction to Dart

#flydart #gdgac

pub

• A package manager

• Integrated right from the start

• 670+ packages

Page 36: Introduction to Dart

#flydart #gdgac

Dart. Right now.

• dart2js compiles Dart to JavaScript

• at least until the DartVM isavailable within all platforms

Page 37: Introduction to Dart

#flydart #gdgac

Ready to get started? Write a Dart app!

(after a short break)

Page 38: Introduction to Dart

#flydart #gdgac

Codelab

Page 39: Introduction to Dart

#flydart #gdgac

Codelab

Page 40: Introduction to Dart

#flydart #gdgac

Hackathon

Page 41: Introduction to Dart

#flydart #gdgac

Hackathon Winners

Page 42: Introduction to Dart

#flydart #gdgac

Please fill out the evaluation form