self: the power of simplicity david ungar and randall b. smith presenter: jonathan aldrich 15-819

18
Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Upload: maximillian-waters

Post on 23-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Self:The Power of Simplicity

David Ungar and Randall B. Smith

Presenter: Jonathan Aldrich

15-819

Page 2: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

History: Smalltalk

• First “modern” OO language – Alan Kay, 1970s– Everything is an object (e.g., the number 15, the class List)– Garbage collection– Closures

• Exploratory programming– Designed for kids– Dynamically typed– Add new code/evaluate exprs with no compilation required

• Extraordinary development environment– 10-20 years ago, better than the best IDE today

• Try it (Squeak)

Page 3: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Self’s Simplicity

• No classes (clone objects instead)

• No variables (use messages)

• No control structures (use polymorphism)

• Everything is an object

Page 4: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Classes vs. Prototypes

• Classes– Hold behavior

– Inherit from another class

– Can be instantiated

• Objects– Hold state

– Are an instance of a class

• Prototypes– Hold behavior

– Delegate (inherit) to another object

– Can be cloned

– Hold state

Page 5: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Classes vs. Prototypes

Page 6: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Instantiation vs. Cloning

Page 7: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Self Flexibility

Page 8: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Control Structures

Page 9: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Modeling closures

• Just prototype objects– Cloned when closure is invoked– Slots for local variables– parent pointer refers to enclosing environment

• For closures, just the enclosing method

• For methods, set to receiver object

Page 10: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Closures

Page 11: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Multiple Inheritance

Page 12: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Code Example

Page 13: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Expressiveness

• Examples in paper– Sharing state between objects– Singleton objects– Easily replace variable with method

• Run-time behavior changes– Add/remove methods– Dynamic Inheritance: Add/remove/change

parent links

Page 14: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Dynamic Inheritance Example

ReactorController

parent*…

NormalController

operate = { … if (badness) parent*: SafetyController … }

SafetyController

restart = { … if (safe condition) parent*: NormalController … }

Page 15: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Checking

• Dynamically typed– Errors are caught at run time

• This slide is largely a placeholder– Will be important part of discussion in other

papers

Page 16: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Claimed Engineering Benefits(in addition to expressiveness)

• Concreteness of prototypes

• Simplicity of cloning

• [Eliminates infinite meta-regress of Smalltalk]

Page 17: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Engineering Challenges

• Are classes too useful to programmers to give up?

• Difficulty of reasoning about dynamism

• Typechecking [Andi’s research]

Page 18: Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich 15-819

Secret Agenda

• Development of new language: Plaid– Prototype-based

• Unifies objects, classes, modules

– Type-safe dynamic inheritance– Other features

• Multi-methods, aspects, typestate, ownership

• Emphasis: safe component-based SE