real and ideal: dart and newspeak, languages for the ......in newspeak, we have to go deeper all...

52
Real and Ideal: Dart and Newspeak, Languages for the Network Age Gilad Bracha Google 1 Friday, December 6, 13

Upload: others

Post on 30-May-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Real and Ideal: Dart and Newspeak, Languages for the Network AgeGilad BrachaGoogle

1Friday, December 6, 13

Page 2: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 3: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 4: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 5: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 6: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Shared Ideas

Pure Object Orientation

Classes

Mixin based Inheritance

Reflection via Mirrors

Live IDEs

Optional Typing

Actor style Concurrency

6Friday, December 6, 13

Page 7: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Different Constraints

Dart must be

Instantly familiar to mainstream programmers

Compile to small, fast Javascript

Has lots of resources

7Friday, December 6, 13

Page 8: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Different Constraints

Newspeak

Has almost no resources

Needs to be reasonably efficient

Can be as unconventional as needed/desired

8Friday, December 6, 13

Page 9: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Shared Ideas

Pure Object Orientation

Classes

Mixin based Inheritance

Reflection via Mirrors

Live IDEs

Optional Typing

Actor style Concurrency

9Friday, December 6, 13

Page 10: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 11: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 12: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 13: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Shared Ideas

Pure Object Orientation

Classes

Mixin based Inheritance

Reflection via Mirrors

Live IDEs

Optional Typing

Actor style Concurrency

13Friday, December 6, 13

Page 14: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 15: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 16: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 17: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 18: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Constructors

One cannot easily abstract over instance creation, e.g.

replace classes with factory objects

Major cause of dependency injection :-(

18Friday, December 6, 13

Page 19: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Constructors

Dart uses constructors because they are familiar: new Point(0, 0);

19Friday, December 6, 13

Page 20: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 21: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Statics

Static members are familiar

Alternatives

Instance members on the class object

Instance members on the outer class

21Friday, December 6, 13

Page 22: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 23: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 24: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 25: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 26: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Classes in Newspeak

Nest arbitrarily (but not like in Java!)

26Friday, December 6, 13

Page 27: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Modularity in Dart

library combinatorialParsing;

import ‘dart:mirrors’;

class CombinatorialParser { ... }

class AlternatingParser extends CombinatorialParser {...}

27Friday, December 6, 13

Page 28: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Modularity in Dart

library combinatorialParsing;

import ‘dart:mirrors’ show InstanceMirror;

class CombinatorialParser { ... }

class AlternatingParser extends CombinatorialParser {...}

28Friday, December 6, 13

Page 29: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Modularity in Dart

library combinatorialParsing;

import ‘dart:mirrors’ as mirrors show InstanceMirror;

class CombinatorialParser { ... }

class AlternatingParser extends CombinatorialParser {...}

29Friday, December 6, 13

Page 30: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Modularity in Newspeak

class CombinatorialParsing usingPlatform: platform = (

| private ObjectMirror = platform mirrors ObjectMirror. |

) (

class CombinatorialParser = ...

class AlternatingParser = CombinatorialParser (...)(...)

...

)

30Friday, December 6, 13

Page 31: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 32: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

32Friday, December 6, 13

Page 33: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Modules are Sandboxes

Factory method parameters are objects/capabilities that determine per-module sandbox

33Friday, December 6, 13

Page 34: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 35: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Multiple Implementations

Modules are objects, accessed via an interface

Different implementations can co-exist

35Friday, December 6, 13

Page 36: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Mixins

All superclasses are virtual

Hence, all class declarations are mixins

In particular, all module definitions are mixins

36Friday, December 6, 13

Page 37: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Class Hierarchy Inheritance

All nested classes are virtual classes Hence, entire libraries/frameworks can be inherited, mixed-in, overridden

37Friday, December 6, 13

Page 38: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 39: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Shared Ideas

Pure Object Orientation

Classes

Mixin based Inheritance

Reflection via Mirrors

Live IDEs

Optional Typing

Actor style Concurrency

39Friday, December 6, 13

Page 40: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Reflection via Mirrors

Traditional reflection:

anObject.getClass().getMembers();

Mirror based reflection:

reflect(anObject).type.members;

40Friday, December 6, 13

Page 41: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Reflection via Mirrors

Advantages

Security

Distribution

Deployment

Disadvantages

Verbosity

41Friday, December 6, 13

Page 42: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 43: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 44: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Beyond Introspection

Mirror builders support modifying running code

StackMirrors and ThreadMirrors support debugging, continuations

44Friday, December 6, 13

Page 45: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 47: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

Shared Ideas

Pure Object Orientation

Classes

Mixin based Inheritance

Reflection via Mirrors

Live IDEs

Optional Typing

Actor style Concurrency

47Friday, December 6, 13

Page 48: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 49: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 50: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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

Page 51: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

To Learn More

http://dartlang.org

http://newspeaklanguage.org

51Friday, December 6, 13

Page 52: Real and Ideal: Dart and Newspeak, Languages for the ......In Newspeak, we have to go deeper All names are late bound; every name is a dynamically dispatched method invocation “Everything

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