27. Alternatives
• CoffeScript & Friends: only improve syntax
• Closure: structure but same semantics
• GWT: good but slow edit/refresh cycle (fixed in
upcoming version!)
|
49. Towards a Better Language
• Optional types
• Mixins (class A extends B with C)
• Method cascades (foo..bar(1)..baz(2))
• Future proof APIs
|
50. Towards a Better Language
• Optional types
• Mixins (class A extends B with C)
• Method cascades (foo..bar(1)..baz(2))
• Future proof APIs
|
51. Future Proof APIs
class Point { // now polar coordinates
double angle, radius;
Point(this.angle, this.radius);
…
}
How do we prevent clients from breaking?
|
52. Future Proof APIs
class Point { // now polar coordinates
get x => …
set x(value) => …
operator [](int index) => …
toString([bool asJson]) => …
}
|
53. Future Proof APIs
class Point { // now polar coordinates
get x => …
set x(value) => …
Getters / Setters
operator [](int index) => …
toString([bool asJson]) => …
}
|
54. Future Proof APIs
class Point { // now polar coordinates
get x => …
set x(value) => …
Getters / Setters
operator [](int index) => …
toString([bool asJson]) => …
}
|
Operator
overriding
55. Future Proof APIs
class Point { // now polar coordinates
get x => …
set x(value) => …
Getters / Setters
operator [](int index) => …
Operator
overriding
toString([bool asJson]) => …
}
|
Optional
arguments
56. Future Proof APIs
class Point { // now polar coordinates
factory Point(x, y) {
return new Point.polar(…);
}
Factory
constructors
Point.polar(angle, radius) { … }
}
|
57. Future Proof APIs
class Point { // now polar coordinates
factory Point(x, y) {
return new Point.polar(…);
}
Factory
constructors
Point.polar(angle, radius) { … }
}
|
Named
constructors
58. Not Just a Language
• Modern, consistent library (collections, typed
HTML bindings, futures, streams, ...)
• JS interoperability
• Server-side programming
|
72. Web Components
<messages>
<message>
<subject>
Please fill out the TPS report
</subject>
<sent>2012-10-03</sent>
<summary>
I'm going to have to ask you to come in...
</summary>
</message>
<message>
<subject>
Reminder: fill out that TPS report!
</subject>
<sent>2012-10-04</sent>
<summary>
It's been 24 hours...
</summary>
</message>
...
</messages>
|
107. Data Binding
<polymer-element name="click-counter">
<template>
<button on-click="increment">Click Me</button>
<p>You clicked the button {{count}} times.</p>
</template>
<script src="click_counter.dart" type="…" ></script>
</polymer-element>
@CustomTag('click-counter')
class ClickCounterElement extends PolymerElement {
@observable int count = 0;
void increment(Event e, var detail, Node target) {
count += 1;
}
}
|
108. Data Binding
<polymer-element name="click-counter">
<template>
<button on-click="increment">Click Me</button>
<p>You clicked the button {{count}} times.</p>
</template>
<script src="click_counter.dart" type="…" ></script>
</polymer-element>
@CustomTag('click-counter')
class ClickCounterElement extends PolymerElement {
@observable int count = 0;
void increment(Event e, var detail, Node target) {
count += 1;
}
}
|
109. Real World Example
data List<A> = Nil | Cons(A x, List<A> xs)
class List<A> { … }
class Nil<A> extends List<A> { … }
class Cons<A> extends List<A> { … }
|
114. Real World Example
<h2>Profit</h2>
<code>
<pre id='generated'>
{{generated}}
</pre>
</code>
String get generated {
final config = new Config(finalFields, … );
return generate(input, config);
}
|