Self: The Power of Simplicity David Ungar and Randall B. Smith Presenter: Jonathan Aldrich
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)
Self’s Simplicity No classes (clone objects instead) No variables (use messages) No control structures (use polymorphism) Everything is an object
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
Classes vs. Prototypes
Instantiation vs. Cloning
Self Flexibility
Control Structures
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
Closures
Multiple Inheritance
Code Example
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
Dynamic Inheritance Example ReactorController parent* … NormalController operate = { … if (badness) parent*: SafetyController … } SafetyController restart = { … if (safe condition) parent*: NormalController … }
Checking Dynamically typed –Errors are caught at run time This slide is largely a placeholder –Will be important part of discussion in other papers
Claimed Engineering Benefits (in addition to expressiveness) Concreteness of prototypes Simplicity of cloning [Eliminates infinite meta-regress of Smalltalk]
Engineering Challenges Are classes too useful to programmers to give up? Difficulty of reasoning about dynamism Typechecking [Andi’s research]
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