a walk on the dart side€¦ · gradual typing 11. a brief history of non-mandatory types common...
TRANSCRIPT
![Page 1: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/1.jpg)
A Walk on the Dart Side
A Quick Tour of ext
Gilad BrachaJoint Work with the Dart Team
1
![Page 2: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/2.jpg)
Dart at 50,000 feet
Language for Web Programming
Sophisticated Web Applications need not be a tour de force
2
![Page 3: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/3.jpg)
Constraints
Instantly familiar to the mainstream programmer
Efficiently compile to Javascript
3
![Page 4: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/4.jpg)
Dart in a Nutshell
Purely Object-Oriented, optionally typed, class-based, single inheritance with actor-based concurrency
4
![Page 5: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/5.jpg)
So what’s so interesting?
Pure Object-Oriented, optionally typed, class-based, single inheritance with actor-based concurrency
5
![Page 6: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/6.jpg)
Some Modest Innovations
Optional types
Built-in Factory Support
ADTs without types
6
![Page 7: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/7.jpg)
Some Modest Innovations
Optional types
ADTs without types
Built-in Factory Support
7
![Page 8: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/8.jpg)
Some Modest Innovations
Optional types
ADTs without types
Built-in Factory Support
8
![Page 9: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/9.jpg)
Mandatory Types Optional Types
9
![Page 10: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/10.jpg)
Mandatory Types
Static type system regarded as mandatory
Maltyped programs are illegal
10
![Page 11: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/11.jpg)
A Brief History of non-mandatory Types
Common Lisp
Scheme (soft typing)
Cecil
Erlang
Strongtalk
BabyJ
Gradual Typing
11
![Page 12: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/12.jpg)
A Brief History of non-mandatory Types
Common Lisp
Scheme (soft typing)
Cecil
Erlang
Strongtalk
BabyJ
Gradual Typing
12
![Page 13: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/13.jpg)
Optional Types
Syntactically optional
Do not affect run-time semantics
13
![Page 14: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/14.jpg)
What does it look like?
14
![Page 15: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/15.jpg)
Mandatory Types: Pros In order of importance:
Machine-checkable documentation
Types provide conceptual framework
Early error detection
Performance advantages
15
![Page 16: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/16.jpg)
Mandatory Types: Cons Expressiveness curtailed
Imposes workflow
Brittleness
16
![Page 17: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/17.jpg)
Optional Types: Can we have our Cake and Eat it Too?
Documentation (for humans and machines- but not verifiable)
Types provide conceptual framework
Early error detection
Performance advantages (much attenuated)
17
![Page 18: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/18.jpg)
Optional Typing Precludes ...
Type-based overloading
Type based initialization, e.g.,
int i; cannot mean var i: int = 0;
Type classes, C# extension methods ...
18
![Page 19: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/19.jpg)
So what’s actually new?
Didn’t we have all this in Strongtalk in 1993?
19
![Page 20: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/20.jpg)
Type Assertion Support
Dart’s optional types are best thought of as a type assertion mechanism, not a static type system
20
![Page 21: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/21.jpg)
Dart Types at Runtime• During development one can choose to validate types
• T x = o; assert(o === null || o is T);
• By default, type annotations have no effect and no cost
• Code runs free
21
![Page 22: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/22.jpg)
Checked Mode
22
![Page 23: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/23.jpg)
Not your Grandfather’s Type System
Not a type system at all -
rather a static analysis tool based on heuristics, coupled to a type assertion mechanism
23
![Page 24: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/24.jpg)
What about a real, sound, type system?
There is no privileged type system, but pluggable types are possible
For example, one can write a tool that interprets existing type annotations strictly
24
![Page 25: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/25.jpg)
Runtime dependent on Type System
Type CheckingExecution
25
![Page 26: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/26.jpg)
Runtime Independent of Type System
Type CheckingExecution
26
![Page 27: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/27.jpg)
What about type inference?
Type Inference relates to Type Checking as Type Checking to Execution
Type inference best left to tools
27
![Page 28: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/28.jpg)
Type System dependent on Type Inference
Type Checking Type Inference
28
![Page 29: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/29.jpg)
Type System Independent of Type Inference
Type Checking Type Inference
29
![Page 30: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/30.jpg)
Don’t get Boxed-In
Type CheckingType
Inference
Type Checking
Execution
30
![Page 31: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/31.jpg)
Interfaces
Every class induces an implicit interface
Interfaces are reified at runtime
Type tests are interface based
You can implement the interface of another class without subclassing it
31
![Page 32: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/32.jpg)
Generics
Reified
Covariant subtyping
Yes, Virginia, it isn’t sound
32
![Page 33: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/33.jpg)
Optional Types and Reified Types
Annotations do not affect semantics
Type arguments to constructors? Interfaces?
33
![Page 34: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/34.jpg)
Optional Types and Reified Types
Annotations do not affect semantics
Type arguments to constructors? Interfaces?
Type Arguments to constructors are optional, but are reified
Type tests are a dynamic construct that relies on reified interfaces
34
![Page 35: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/35.jpg)
Summary: Optional Types • Static checker provides warnings; tuned to be unobtrusive
• Type annotations have no effect except ...
• During development, you can check dynamic types against declarations
35
![Page 36: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/36.jpg)
But is it Dynamic?
noSuchMethod
Mirrors & Debugging
36
![Page 37: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/37.jpg)
Some Modest Innovations
Optional types
ADTs without types
Built-in Factory Support
37
![Page 38: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/38.jpg)
Libraries and ADTs
A Library is a set of top-level classes, interfaces and functions
Libraries may be be mutually recursive
Libraries are units of encapsulation
38
![Page 39: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/39.jpg)
Libraries and ADTs
Library based privacy
- based on names
- _foo is private to the library
- naming and privacy are not orthogonal :-(
- privacy can be recognized context-free :-)
39
![Page 40: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/40.jpg)
Interfaces vs. ADTs
How to reconcile?
- interfaces based on externally visible behavior
- ADTs based on implementation
40
![Page 41: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/41.jpg)
Interfaces vs. ADTsWhat happens when we implement an interface with private members?
// in library 1
class A { var _foo = 0;}
foo(A a) => a._foo;
// in library 2
class B implements A {int get _foo()=> 42;}
foo(new B());
41
![Page 42: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/42.jpg)
Interfaces vs. ADTsWhat happens when we implement an interface with private members?
// in library 1
class A { var _foo = 0;}
foo(A a) => a._foo
// in library 2
class B implements A {int get _foo()=> 42;} // Warning?
foo(new B());
42
![Page 43: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/43.jpg)
Interfaces vs. ADTsWhat happens when we implement an interface with private members?
// in library 1
class A { var _foo = 0;}
foo(A a) => a._foo; // Warning?
// in library 2
class B implements A {int get _foo()=> 42;}
foo(new B());
43
![Page 44: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/44.jpg)
Interfaces vs. ADTsclass B implements A {
int get _foo()=> 42;
noSuchMethod(msg){
msg.name = ‘_foo’ ?msg.sendTo(this): super.noSuchMethod(msg);
}
}
44
![Page 45: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/45.jpg)
Some Modest Innovations
Optional types
ADTs without types
Built-in Factory Support
45
![Page 46: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/46.jpg)
FactoriesConstructors without tears
Use caches, return other types of objects
Instance creation expressions based on interfaces
Minimize need for Dependency Injection
46
![Page 47: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/47.jpg)
Factories
47
![Page 48: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/48.jpg)
Dart is not Done• Mixins?
• Reflection
• High level actor semantics: await? Erlang-style pattern matching? Promise-pipelining?
• Class nesting? First class libraries? Non-nullable types?
• Metadata? Pluggable types?
48
![Page 49: A Walk on the Dart Side€¦ · Gradual Typing 11. A Brief History of non-mandatory Types Common Lisp Scheme (soft typing) Cecil Erlang Strongtalk BabyJ Gradual Typing 12. Optional](https://reader033.vdocuments.mx/reader033/viewer/2022042922/5f6e58960f63da4e6f30628f/html5/thumbnails/49.jpg)
Q & A49