Self Introduction
Ellen.Van.Paesschen@vub.ac.be Programming Technology Lab - Vrije Universiteit Brussel Dynamic Languages DaySelf Introduction Dynamic Languages Day - - PowerPoint PPT Presentation
Self Introduction Dynamic Languages Day - - PowerPoint PPT Presentation
Self Introduction Dynamic Languages Day Ellen.Van.Paesschen@vub.ac.be Programming Technology Lab - Vrije Universiteit Brussel Schedule Introduction to prototypes Important features of PBLs History of Self Selfs basics The power of Self
Schedule
Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency ReferencesIntroduction To Prototypes
“Using Prototypical Objects to Implement Shared Behavior in OO Systems“Schedule
Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency ReferencesImportant Features of PBLs (1/3)
Three ways to create new objects Creation ex-nihilo Extension Cloning a prototype
Important Features of PBLs (2/3)
Delegation or object-centered inheritance
delegates to a prototypical Turtle at (25,200) with heading 90 *forward x 25 heading 90 E x e c u t e d i n c- n
- f
- r
draw
LOGO exampleImportant Features of PBLs (3/3)
Parent sharing
200 (50 , 200) (100 , 200) (50 , 200)y: 100
100 (100 , 100) (50 , 100) (50 , 100) a Pen at a Pen at a Turtle at with heading 90 x y 50 *draw heading 90 *draw *forward x 100 selfSchedule
Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency ReferencesHistory of
1986 1995 1993 1987 1992 1991 1990 Designed by Ungar&Smith @ XEROX “Self: The Power of Simplicity” @OOPSLA'87 Initial implementation @Stanford 1st Public release Stanford Moved to More public releases Self 4.2.1 Self 4.0 Research vehicle Researched@Sun todaySchedule
Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency ReferencesSelf’s Basics
Visual exploratory programming environment Desktop An object Input An object TrashSelf’s Basics
Language features (1/2) Syntax and semantics resemble those of Smalltalk Blocks Everything is an object Manipulated via message sending Objects consist of slots Slots contain data or methods Assignable and constant data slotsSelf’s Basics
Language features (2/2) Default creation is cloning prototype via copy Creation ex-nihilo via slot definition, e.g. (|x . y <- 5|) Delegation for behavioral inheritance Through parent slots, e.g. parent1* Extension (concatenation) for state inheritance copy-downSelf’s Basics
Traits objects gather shared reusable behavior Traits Pen draw x y 50 200 prototypical Pen Delegation via parent* pointer x y a Pen copy 50 200 x y a Pen copy 50 200Convention
Self’s Basics
Maps transparently group objects x y 50 200 prototypical Pen a Pen copy 100 200 a Pen copy 20 30Clone family
- ffset
- ffset
Self’s Basics
Dynamic delegation becomeDashed Traits Turtle a Turtle at (50,200) with heading 90 x y 50 draw heading 90 forward 200 backward Traits DashedTurtle drawSelf’s Basics
Multiple inheritance Traits MovingTurtle a Turtle at (50,200) with heading 90 x y 50 heading 90 forward 200 Traits DrawingTurtle draw backwardSchedule
Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency ReferencesThe Power of Self
Reflective meta-programming with mirrors x y 50 200 a Pen a P reflectee asMirror addSlots: |(z <- 0)| z a mirror on a Pen Annotations Consulting size, parents, ... Changing structure Testing ...The Power of Self
Example 1: Method overwriting Traits Pen draw = (body) x y 50 200 asMirror a mirror on Traits Pen draw=(newBody) at: ‘draw’ PutContents: (reflect:(newBody)) x y a Pen 50 10 x y a Pen 1 3 a Pen draw=(body) draw = (newBody)The Power of Self
Example 2: Assignment shadowing (1/3) Traits Pen draw = (body) x y 50 200 x y a Pen 50 10 x y a Pen 1 3 a Pen Setters are automatically provided per assignable slot via a hidden data slot containing the assignment primitive x: = ( ) y: = ( ) ➔ ➔ x: = ( ) y: = ( ) ➔ ➔ x: = ( ) y: = ( ) ➔ ➔ How to intercept this x: ?The Power of Self
Example 2: Assignment shadowing (2/3) x y 50 200 x y a Pen 50 10 x y a Pen 1 3 x:val = ([new code] resend.x:val) a Pen a mirror on a Pen asMirror reflectee a Pen reflectee Create a new object Add a parent link to original Pen Change all references from original Pen to new object Add new method possibly with super call x:5 x: = ( ) y: = ( ) ➔ ➔ x: = ( ) y: = ( ) ➔ ➔ x: = ( ) y: = ( ) ➔ ➔ How to- verride this x: ?
The Power of Self
Example 2: Assignment shadowing (3/3) Create a new object Add a parent link to original Pen Change all references from original Pen to new wrapper a new object Add new method possibly with super callSix statements
shadow: selector = ( |new . me| me: (reflect: self). new: (reflect: (| |)). new at:(selector,':') PutContents: (('|:arg| resend.',selector, ': arg. \'new code\'.') parseObjectBody). (browse referencesOf: self)do:[ |:ref| (ref isFake) ifFalse:[(ref mirror)at:(ref storedName PutContents:new]]. new at:(selector,'assignmentParent') PutContents: (reflect:self). (new at:(selector,'assignmentParent')) isParent: true.)Schedule
Introduction to prototypes Important features of PBLs History of Self Self’s character The power of Self Efficiency ReferencesEfficiency
Is Self slow? Significant optimisations of the Self compiler by Chambers and Hölzle @ Sun Branch prediction Optimisation of the fetch-decode-execute processor cycle for branch instructions Inline caching Traits containing the intended behavior are ``guessed” during method lookup ≈ 2 * speed of optimised CSchedule
Introduction to prototypes Important features of PBLs History of Self Self’s character The power of Self Efficiency ReferencesReferences
Self homepage http://research.sun.com/research/self Self 4.2.1 http://research.sun.com/research/self/release_4.2/release.html Self online tutorial - Wolzcko, De Corte http://research.sun.com/research/self/release_4.0/Self-4.0/Tutorial/index.html SelfSync: a RTE environment in Self http://prog.vub.ac.be/~ellenvp Self SWIKI http://www.merlintec.com:8080/Self Self Programmer’s Reference Manual Self folder /manualsReferences
Programming as an Experience: The Inspiration for Self (1995) - Smith, Ungar Self: The Power of Simplicity (1987) - Ungar, Smith Parents are Shared Parts: Inheritance and Encapsulation in Self (1991) - Chambers, Ungar, Chang, Hölzle Organizing Programs Without Classes (1991) - Ungar, Chambers, Chang, HölzleQuestions