Dart @ JUG Saxony

38
Christian Grobmeier http://www.grobmeier.de @grobmeier versus Donnerstag, 26. April 2012

description

An old talk on #Dartlang which I gave at the Java Usergroup in Dresden. Meanwhile my slide style is improved by the fantastic book "Presentation Zen" (see my other slides here)

Transcript of Dart @ JUG Saxony

Page 1: Dart @ JUG Saxony

Christian Grobmeierhttp://www.grobmeier.de

@grobmeier

versus

Donnerstag, 26. April 2012

Page 2: Dart @ JUG Saxony

• Programmiersprache von Google

• Kann JS ersetzen

• Läuft in einer VM

• Für „ernsthafte“ Anwendungen

• Jung und rockt

• Heavy Metal Band aus England

• Ersetzt Hawkwind

• Läuft mit Whisky

• Zur täglichen Anwendungen

• Alt und rockt

Donnerstag, 26. April 2012

Page 3: Dart @ JUG Saxony

Lemmy

Bass + Gesang

Wizzo

Schlagzeug

Mikkey Dee

Gitarre

Band

Donnerstag, 26. April 2012

Page 4: Dart @ JUG Saxony

Dart SDK

Dartium

Dart Editor

Band

Donnerstag, 26. April 2012

Page 5: Dart @ JUG Saxony

Releases

21 Studioalben!

+ unzähliges mehr

Lang Spec v0.08 :-(

kaum Libraries :-(

Donnerstag, 26. April 2012

Page 6: Dart @ JUG Saxony

Highlights

+ 17 mehr!

Donnerstag, 26. April 2012

Page 7: Dart @ JUG Saxony

Dart ist „Mainstream“, hat eine main-Methode und kennt nur ein

null.

Highlights

Donnerstag, 26. April 2012

Page 8: Dart @ JUG Saxony

Dart kennt Interfaces und Klassen

Highlights

Donnerstag, 26. April 2012

Page 9: Dart @ JUG Saxony

class MyReceiver extends Isolate {}

interface Hobbit extends A, B{}

class Frodo implements Hobbit, Hungry {}

Einfachvererbung

Mehrvererbung

Highlights

Donnerstag, 26. April 2012

Page 10: Dart @ JUG Saxony

Dart kennt optionale Typen

Highlights

dart --enable_type_checks App.dart

Donnerstag, 26. April 2012

Page 11: Dart @ JUG Saxony

class Frodo {var hungry;bool sleepy;Ring ring;

}

Dynamic

Highlights

Donnerstag, 26. April 2012

Page 12: Dart @ JUG Saxony

Dart does not need to drink whisky.

It has whisky in it‘s veins.

Highlights

Donnerstag, 26. April 2012

Page 13: Dart @ JUG Saxony

class Frodo {Frodo(num age) : super() {}

}

var frodo = new Frodo(111);

Konstruktor

Highlights

Donnerstag, 26. April 2012

Page 14: Dart @ JUG Saxony

class Frodo {Frodo.eat(){}

}var frodo = new Frodo.eat();

Ein „named Constructor“ verhält sich wie ein überladener

Konstruktor in Java.

Highlights

Donnerstag, 26. April 2012

Page 15: Dart @ JUG Saxony

class Frodo { var hungry;

Frodo.cook(this.hungry);}

new Frodo.cook(true);

Highlights

Donnerstag, 26. April 2012

Page 16: Dart @ JUG Saxony

class Frodo { bool _hungry;

bool get hungry() => _hungry;void set hungry(bool x) {_hungry = x;

}}

Get/Set kann nicht überschrieben werden und können nicht

überschreiben.

Highlights

Donnerstag, 26. April 2012

Page 17: Dart @ JUG Saxony

Frodo f = new Frodo();f.hungry = true;

Setter werden wie Standardproperties aufgerufen.

GET/SET Methoden vermeiden!

Highlights

Donnerstag, 26. April 2012

Page 18: Dart @ JUG Saxony

class Hobbit { factory Hobbit() { return new Hobbit._internal(); }

Hobbit._internal() { print("Construct");! }}

main() { Hobbit hobbit = new Hobbit();}

Das Factory Pattern mit Dart

Highlights

Donnerstag, 26. April 2012

Page 19: Dart @ JUG Saxony

Dart ist Library-Scoped

Highlights

Donnerstag, 26. April 2012

Page 20: Dart @ JUG Saxony

class Frodo {eat(){ }_sleep() { }

}

Public

Private

PrivacyHighlights

Donnerstag, 26. April 2012

Page 21: Dart @ JUG Saxony

#library(„Frodo“);class Frodo {...

Public

Private Elemente sind nicht sichtbar

#library(„Mordor“);#import(„Frodo.dart“);new Frodo()...

PrivacyHighlights

Donnerstag, 26. April 2012

Page 22: Dart @ JUG Saxony

Dart Isolates

Highlights

Donnerstag, 26. April 2012

Page 23: Dart @ JUG Saxony

Threads => Isolates

• Isolates erlauben „multithreading“

• Isolates kommunizieren via Ports

• Isolates werden durch „spawn“ing erzeugt

Donnerstag, 26. April 2012

Page 24: Dart @ JUG Saxony

<body><script type="application/dart">main() {

// Do some DART } </script><script type="application/dart">main() { }

</script></body>

Isolate

Isolates

Donnerstag, 26. April 2012

Page 25: Dart @ JUG Saxony

Isolates

Light Heavy

•Leben im gleichen Thread•Nur ein Isolate auf einmal

•Erzeugen einen neuen Thread•Mehrere Isolates auf einmal

Dart entscheidet über den Geschmack.Isolates können keine States teilen!

Isolates sind immer asynchron!

Donnerstag, 26. April 2012

Page 26: Dart @ JUG Saxony

process() { port.receive((var m, SendPort r) { print ("Got message: ${m}"); r.send("close"); port.close(); });}

Isolates

Donnerstag, 26. April 2012

Page 27: Dart @ JUG Saxony

main() { port.receive((var m, SendPort r) { print("Got message: ${m}");! port.close(); });

! SendPort s = spawnFunction(process); s.send("start", port.toSendPort());}

Isolates

Donnerstag, 26. April 2012

Page 28: Dart @ JUG Saxony

• Kein Multithreading - einmal Motörhead, immer Motörhead

• Mit Motörhead ist man niemals einsam

• Ist der eine Thread einmal beendet, gibt es keine neuen Alben mehr

Donnerstag, 26. April 2012

Page 29: Dart @ JUG Saxony

Road Crew

• HTML

• Templates

• JSON

• Dartdoc

• Frog

• etc. • We are the Road Crew

• Unbekannte Personen

Donnerstag, 26. April 2012

Page 30: Dart @ JUG Saxony

HTML Library

document.query('#myid');document.query('.foo');document.queryAll('.foo');

Inspiriert von jQuery

Donnerstag, 26. April 2012

Page 31: Dart @ JUG Saxony

HTML Library

elem.attributes.contains('name');elem.attributes['name'];elem.attributes['name'] = 'value';elem.attributes.remove('name');

Collections!

Donnerstag, 26. April 2012

Page 32: Dart @ JUG Saxony

HTML Library

new Element.tag('div');

TableElement t = new Element.html('<table><tr><td>Hi</td></tr></table>');

Verbesserte Elementerstellung - mit Konstruktoren

Donnerstag, 26. April 2012

Page 33: Dart @ JUG Saxony

HTML Library

elem.on.click.add( (event) => print('click!'));

elem.on.click.remove(listener);

Alle Events sind in einem Property erreichbar.

Donnerstag, 26. April 2012

Page 34: Dart @ JUG Saxony

Templates

Hello.tmpl Hello.dart

App.dart

App.html

Donnerstag, 26. April 2012

Page 35: Dart @ JUG Saxony

Templates

template Hello(String to) { <div>${to}</div>}

$ template Hello

Donnerstag, 26. April 2012

Page 36: Dart @ JUG Saxony

Templates

main() { Hello h = new Hello("Motörhead"); var panel = document.query("#p"); panel.elements.add(h.root);}

Donnerstag, 26. April 2012

Page 37: Dart @ JUG Saxony

And the winner is...

OffenheitStabile API

Template SystemReleasesZukunft

BrowserübergreifendAndroid SupportGeschwindigkeit

Lautstärke

Unent

schie

den

Donnerstag, 26. April 2012

Page 38: Dart @ JUG Saxony

Röck ön!Danke!

Christian Grobmeierhttp://www.grobmeier.de

@grobmeier

Donnerstag, 26. April 2012