42
The State of D art Gilad Bracha Google 1 Wednesday, April 24, 13

The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

The State of D artGilad BrachaGoogle

1Wednesday, April 24, 13

Page 2: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

The State of DartGilad BrachaGoogle

2Wednesday, April 24, 13

Page 3: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Dart

Web apps should be as good or better than native apps

For users

For developers

Sophisticated web apps need not require superhuman feats of heroism

3Wednesday, April 24, 13

Page 4: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Dart

Constraints

Compile to Javascript on the browser

Familiar to mainstream programmers

4Wednesday, April 24, 13

Page 5: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Dart: Language, Platform, Tools, Engine(s)

Familiar, unsurprising language

5Wednesday, April 24, 13

Page 6: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

class Point {

var x, y;

Point(a, b){x =a; y = b;};

operator +(a) { return new Point(x + a.x, y + a.y);}

}

6Wednesday, April 24, 13

Page 7: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Dart: Language, Platform, Tools, Engine(s)

There are umpteen frameworks for any given purpose on the web. They don’t interoperate very well

Dart provides a solid set of core libraries. The core APIs are now stable.

7Wednesday, April 24, 13

Page 8: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Dart: Language, Platform, Tools, Engine(s)

Language is designed to be toolable

Dynamic, but structured enough to support analysis

Classes

No eval()

Optional types

8Wednesday, April 24, 13

Page 9: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

class Point {

var x, y;

Point(a, b){x =a; y = b;};

operator +(a) {return new Point(x + a.x, y + a.y);}

}

9Wednesday, April 24, 13

Page 10: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

class Point {

var x, y;

Point(this.x, this.y);

operator +(a) =>

new Point(x + a.x, y + a.y);

}

10Wednesday, April 24, 13

Page 11: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

class Point {

int x, y;

Point(this.x, this.y);

Point operator +(Point a) =>

new Point(x + a.x, y + a.y);

}

11Wednesday, April 24, 13

Page 12: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Dart: Language, Platform, Tools, Engine(s)

VM now at roughly 2x V8 performance. Fastest dynamic language implementation ever

Compilation to Javascript roughly on par with handwritten JS

12Wednesday, April 24, 13

Page 13: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Dart ExecutionDart

JavaScript Dart VM

dart2js

13Wednesday, April 24, 13

Page 14: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Overview

Dart: Civilized Programming for the Web

Class based, Purely Object Oriented, Optionally Typed, Mixin-based Inheritance, Message-passing Concurrency, Mirror-based Reflection

14Wednesday, April 24, 13

Page 15: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Everything is an Object

As in Smalltalk, Ruby, Scala and others

No autoboxing, no hidden coercions

15Wednesday, April 24, 13

Page 16: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Segue: Coercions

function (x){return x;}(false) ? print(“true”): print(“false”);

16Wednesday, April 24, 13

Page 17: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Segue: Coercions

false is true:

function (x){return x;}(false) ? print(“true”): print(“false”);

17Wednesday, April 24, 13

Page 18: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Segue: Coercions

false is true:

function (x){return x;}(false) ? print(“true”): print(“false”);)

autobox

18Wednesday, April 24, 13

Page 19: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Segue: Coercions

false is true:

function (x){return x;}(false) ? print(“true”): print(“false”);

coerce object to bool

19Wednesday, April 24, 13

Page 20: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Segue: Coercions

false is true:

function (x){return x;}(false) ? print(“true”): print(“false”);

Ignorance is Strength:

All this was known since PL/1 (1960s)

Those who ignore history are condemned to repeat it (cf. Javascript, or worse, PHP)

20Wednesday, April 24, 13

Page 21: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Representation Independence

Fields are never accessed directly in Dart

Instead, accessors (getters and setters) are created and used implicitly

x.a means invoke x’s getter method

get a { ... }

x.a = v means invoke x’s setter method

set a(x) { .... }

21Wednesday, April 24, 13

Page 22: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Representation Independence

Now, if I decide to change the representation of x objects to compute a instead, I can declare getters and setters as needed without breaking my clients. Even my subclasses can’t tell.

22Wednesday, April 24, 13

Page 23: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Optional Types

Types Annotations

Are syntactically optional

Have no semantic effect

23Wednesday, April 24, 13

Page 24: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Types don’t effect Runtime

class LazyFields {

var _x;

get x => _x == null ? _x = complicated(): _x;

}

24Wednesday, April 24, 13

Page 25: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Types don’t effect Runtime

class LazyFields {

int _x;

int get x => _x == null ? _x = complicated(): _x;

}

25Wednesday, April 24, 13

Page 26: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Types are InterfacesDart has no interface declarations, but classes induce implicit interfaces that are reified.

abstract class Pair {get first; get second;}

class ArrayPair implements Pair {

var rep = [];

ArrayPair(a, b) { rep[0] = a; rep[1] = b;}

get first => rep[0]; get second => rep[1];

}

26Wednesday, April 24, 13

Page 27: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Mirrors

27Wednesday, April 24, 13

Page 28: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Classic OO Reflection

o.getClass().getMethods();

28Wednesday, April 24, 13

Page 29: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Mirrors are Different

Mirrors are objects that reflect other objects.

reflect(o).type.methods;

If you don’t have the right mirror, you cannot reflect, addressing difficulties in deployment, distribution, security

29Wednesday, April 24, 13

Page 30: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Mirrors are Different

reflect(o).type.methods;

30Wednesday, April 24, 13

Page 31: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Mirrors are Different

reflect(o).type.methods;

InstanceMirror

31Wednesday, April 24, 13

Page 32: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Mirrors are Different

reflect(o).type.methods;

ClassMirror

32Wednesday, April 24, 13

Page 33: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Mirrors are Different

reflect(o).type.methods;

Map<Symbol, MethodMirror>

33Wednesday, April 24, 13

Page 34: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Beyond Introspection

Mirror builders for creating new/modified code

Stack mirrors and Activation mirrors to support debugging

34Wednesday, April 24, 13

Page 35: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

CaveatsWeb apps often optimized for size by eliminating symbols (minification) and unused code (tree shaking)

Reflecting on code that has been optimized away is not possible

Options:

Do not optimize? Ouch.

Provide mechanism to selectively preserve reflective information

35Wednesday, April 24, 13

Page 36: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Caveats

Web apps often optimized for size by eliminating symbols (minification) and unused code (tree shaking)

Reflecting on code that has been minifed is possible

Using constant symbols, we can ensure that symbols correspond to minified names

Mapping back to real names entails space overhead

36Wednesday, April 24, 13

Page 37: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

A History of Mirrors

Mirror-based Reflection

Originated in Self

Used in Strongtalk, Java (JDI & APT), Newspeak, Scala

Now in Dart

Caveat Emptor: WIP! Coming to dart2js soon!

37Wednesday, April 24, 13

Page 39: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

noSuchMethod()

class Proxy {

final mirror;

Proxy(forwardee): mirror = reflect(forwardee);

noSuchMethod(Invocation i) => mirror.delegate(i);

}

39Wednesday, April 24, 13

Page 40: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

LibrariesLIbraries are Dart’s modularity mechanism

Libraries group classes, functions and variables in a top level scope

Libraries are units of encapsulation, but not security

Privacy is per library. Private members are prefixed with _

So far, libraries are NOT objects :-(

Familiar import mechanism

40Wednesday, April 24, 13

Page 41: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

Dart

Class based, Purely Object Oriented, Optionally Typed, Mixin-based Inheritance, Mirror-based Reflection, Message-passing Concurrency

Supports Software Engineering, Good Performance, Toolability

Status: Open Source (Apache), Open Development

41Wednesday, April 24, 13

Page 42: The State of D art - GOTO Conferencegotocon.com/.../slides/GiladBracha_TheStateOfDart.pdf · 2013-04-25 · Dart: Language, Platform, Tools, Engine(s) VM now at roughly 2x V8 performance

http://www.dartlang.org

42Wednesday, April 24, 13