real and ideal: dart and newspeak, languages for the ......in newspeak, we have to go deeper all...
TRANSCRIPT
Real and Ideal: Dart and Newspeak, Languages for the Network AgeGilad BrachaGoogle
1Friday, December 6, 13
Web Language?
Ideal: There shouldn’t be such a thing - it’s just distributed programming
Real: A lot of adjustments needed to get things to work smoothly in today’s world
2Friday, December 6, 13
Goals and VisionsMake applications better for users
Leverage the network to
• Do digital housekeeping
• Explore, share, collaborate
Make programmers more productive
Improve programming language & platform
3Friday, December 6, 13
Dart’s Vision
Web Apps should be as good as, or better than native apps
Solve pressing problems
Performance
Productivity
Leverage web’s strengths: HTML5, CSS, Open standards, community
4Friday, December 6, 13
Newspeak’s Vision
Full Service Computing (aka Objects as Software Services)
Always Available - online & offline
Always up to date
Synchronize program and data uniformly
Full access to local platform
Uniform platform for web, mobile, desktop
5Friday, December 6, 13
Shared Ideas
Pure Object Orientation
Classes
Mixin based Inheritance
Reflection via Mirrors
Live IDEs
Optional Typing
Actor style Concurrency
6Friday, December 6, 13
Different Constraints
Dart must be
Instantly familiar to mainstream programmers
Compile to small, fast Javascript
Has lots of resources
7Friday, December 6, 13
Different Constraints
Newspeak
Has almost no resources
Needs to be reasonably efficient
Can be as unconventional as needed/desired
8Friday, December 6, 13
Shared Ideas
Pure Object Orientation
Classes
Mixin based Inheritance
Reflection via Mirrors
Live IDEs
Optional Typing
Actor style Concurrency
9Friday, December 6, 13
Pure Object Orientation
Classic formulation from Smalltalk: Everything is an Object
No primitive types
Uniformity has huge benefits; eliminate irregularities and special cases
10Friday, December 6, 13
Pure Object Orientation
In Dart, all runtime values are objects including
null, booleans, numbers, functions, classes
Not all operations are dynamically dispatched
Constructor calls
Static and library member access
11Friday, December 6, 13
Pure Object Orientation
In Newspeak, we have to go deeper
All names are late bound; every name is a dynamically dispatched method invocation
“Everything is an object” follows from “Everything is a virtual method invocation”
12Friday, December 6, 13
Shared Ideas
Pure Object Orientation
Classes
Mixin based Inheritance
Reflection via Mirrors
Live IDEs
Optional Typing
Actor style Concurrency
13Friday, December 6, 13
Classes
Must be part of the language
Prototypes are not the answer (sorry, Self :-( )
Javascript approach of implementing as libraries leads to fragmentation
14Friday, December 6, 13
Classes in Dartclass Point {
var x, y;
Point(a, b){ x = a ; y = b;}
operator +(p){return new Point(x+p.x, y+p.y);}
static distance(p1, p2) {
return sqrt( /* slide is too small */);
}
}
15Friday, December 6, 13
Classes in Dartclass Point {
var x, y;
Point(this.x, this.y);
operator +(p) => new Point(x+p.x, y+p.y);
static distance(p1, p2) {
return sqrt( /* slide is too small */);
}
}
16Friday, December 6, 13
Constructors
Constructors have well know problems: see http://gbracha.blogspot.com/2007/06/constructors-considered-harmful.html
Dart constructors solve many of these
They can return objects from a cache
They can produce instances of subtypes
One can never see uninitialized fields
17Friday, December 6, 13
Constructors
One cannot easily abstract over instance creation, e.g.
replace classes with factory objects
Major cause of dependency injection :-(
18Friday, December 6, 13
Constructors
Dart uses constructors because they are familiar: new Point(0, 0);
19Friday, December 6, 13
Statics
Static methods and variables have well known problems: http://gbracha.blogspot.com/2008/02/cutting-out-static.html
Dart is single threaded, so these are much less acute
20Friday, December 6, 13
Statics
Static members are familiar
Alternatives
Instance members on the class object
Instance members on the outer class
21Friday, December 6, 13
Classes, differentlyclass Point factory new(a, b) {var x = a, y = b;}
{ // instance methods
+(p) => Point.new(x+p.x, y+p.y);
}{ // class methods
distance(p1, p2) {
return ((p1.x - p2.x)**2 + (p1.y - p2.y)**2) .sqrt;
}
}
22Friday, December 6, 13
Classes, differentlyclass Point factory new(a, b) {var x = a, y = b;}
{ // instance methods
+(p) => p.getClass.new(x+p.x, y+p.y);
}{ // class methods
distance(p1, p2) {
return ((p1.x - p2.x)**2 + (p1.y - p2.y)**2) .sqrt;
}
}
23Friday, December 6, 13
Classes, differentlyclass Point factory new(a, b) {var x = a, y = b;}
{ // instance methods
+(p) => Point.new(x+p.x, y+p.y);
}{ // class methods
distance(p1, p2) {
return ((p1.x - p2.x)**2 + (p1.y - p2.y)**2) .sqrt;
}
}
24Friday, December 6, 13
Classes in Newspeakclass Point x: a y: b = ( | x = a. y = b. | ) (
(* instance methods *)
+ p = (^Point x: x+p x y: y+p y)
):( (* class methods *)
distanceFrom: p1 to: p2 = (
^ ((p1 x - p2 x) square + (p1 y - p2 y) square) sqrt
)
)
25Friday, December 6, 13
Classes in Newspeak
Nest arbitrarily (but not like in Java!)
26Friday, December 6, 13
Modularity in Dart
library combinatorialParsing;
import ‘dart:mirrors’;
class CombinatorialParser { ... }
class AlternatingParser extends CombinatorialParser {...}
27Friday, December 6, 13
Modularity in Dart
library combinatorialParsing;
import ‘dart:mirrors’ show InstanceMirror;
class CombinatorialParser { ... }
class AlternatingParser extends CombinatorialParser {...}
28Friday, December 6, 13
Modularity in Dart
library combinatorialParsing;
import ‘dart:mirrors’ as mirrors show InstanceMirror;
class CombinatorialParser { ... }
class AlternatingParser extends CombinatorialParser {...}
29Friday, December 6, 13
Modularity in Newspeak
class CombinatorialParsing usingPlatform: platform = (
| private ObjectMirror = platform mirrors ObjectMirror. |
) (
class CombinatorialParser = ...
class AlternatingParser = CombinatorialParser (...)(...)
...
)
30Friday, December 6, 13
External Dependencies are Explicit
Module definition = Class not nested within another class
No access to surrounding namespace
All names locally declared or inherited from Object
31Friday, December 6, 13
32Friday, December 6, 13
Modules are Sandboxes
Factory method parameters are objects/capabilities that determine per-module sandbox
33Friday, December 6, 13
Side by Side
Module definitions are instantiated into stateful objects known as modules
Easy to create multiple instances, with different parameters
34Friday, December 6, 13
Multiple Implementations
Modules are objects, accessed via an interface
Different implementations can co-exist
35Friday, December 6, 13
Mixins
All superclasses are virtual
Hence, all class declarations are mixins
In particular, all module definitions are mixins
36Friday, December 6, 13
Class Hierarchy Inheritance
All nested classes are virtual classes Hence, entire libraries/frameworks can be inherited, mixed-in, overridden
37Friday, December 6, 13
Why Libraries are not Objects
Low barrier to entry
Reduce implementation uncertainty
We know what class you are instantiating
We know what top level functions and static methods you are calling
Feeds into broader static analysis for dart2js
Maybe in Dart 2.0 ...
38Friday, December 6, 13
Shared Ideas
Pure Object Orientation
Classes
Mixin based Inheritance
Reflection via Mirrors
Live IDEs
Optional Typing
Actor style Concurrency
39Friday, December 6, 13
Reflection via Mirrors
Traditional reflection:
anObject.getClass().getMembers();
Mirror based reflection:
reflect(anObject).type.members;
40Friday, December 6, 13
Reflection via Mirrors
Advantages
Security
Distribution
Deployment
Disadvantages
Verbosity
41Friday, December 6, 13
Mirrors in Dart
Tree shaking and minification pose challenges
If you minify a name, how will you look it up?
Symbols minify with the code
If code is not used at the base level, tree shaking may eliminate it from the deployed version. If we then try and reflect on it, it won’t be available
@MirrorsUsed can help, but it is tricky
42Friday, December 6, 13
Mirrors in Newspeak
The Ministry of Truth does not minify or treeshake
Your code may be a lot larger :-(
In a few years, no one will care
code and data should be sync’ed anyway
43Friday, December 6, 13
Beyond Introspection
Mirror builders support modifying running code
StackMirrors and ThreadMirrors support debugging, continuations
44Friday, December 6, 13
Beyond Introspection
We want to get there in Dart as well!
In the VM, things look good
On dart2js, it’s more complicated
Do you want to download the entire compiler?
Can we do this on optimized JS code?
45Friday, December 6, 13
More on Mirrors
Academic paper: http://www.bracha.org/mirrors.pdf
Video:
http://www.hpi.uni-potsdam.de/hirschfeld/events/past/media/100105_Bracha_2010_LinguisticReflectionViaMirrors_HPI.mp4
46Friday, December 6, 13
Shared Ideas
Pure Object Orientation
Classes
Mixin based Inheritance
Reflection via Mirrors
Live IDEs
Optional Typing
Actor style Concurrency
47Friday, December 6, 13
Live IDEs
The language is only part of the equation; libraries and tools are crucial in the overall experience
A live experience in the Smalltalk tradition needs to be made available to the wider world
48Friday, December 6, 13
Dart Editor
Familiar: based on Eclipse
Immediate feedback
Integrate Dartium - Chromium based browser with Dart VM
Name completion
Refactoring
Hints and Warnings
49Friday, December 6, 13
Hopscotch IDE
Modernize the Smalltalk/Self experience
Far beyond REPL
Object inspectors, workspaces
Live objects always available
Tightly integrates browsing, debugging, source control, unit testing
Innovative UI: browser style navigation
IDE itself fully modifiable by the programmer50Friday, December 6, 13
To Learn More
http://dartlang.org
http://newspeaklanguage.org
51Friday, December 6, 13
This file is licensed under the Creative Commons Attribution ShareAlike 3.0 License. In short: you are free to share and make derivative works of the file under the conditions that you appropriately attribute it, and that you distribute it only under a license identical to this one. Official license.
The Newspeak eye used in the bullets, slide background etc. was designed by Victoria Bracha and is used by permission.
Licensing
52Friday, December 6, 13