Self Introduction Dynamic Languages Day - - PowerPoint PPT Presentation

self introduction
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Self Introduction

Ellen.Van.Paesschen@vub.ac.be Programming Technology Lab - Vrije Universiteit Brussel Dynamic Languages Day
slide-2
SLIDE 2 Dynamic Languages Day

Schedule

Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency References
slide-3
SLIDE 3 Dynamic Languages Day Prototype theory is founded in the middle of the twentieth century as a response to the ancient class theory In 1986 prototypes are introduced into the OO community by Lieberman in “A prototype represents the default behavior for a concept” “New objects can reuse (part of) the prototype’s knowledge by saying how the new object differs from the prototype” PBLs are class-less OO languages Most PBLs are dynamically typed (only Omega isn’t) Self, Kevo, Agora, NewtonScript, ...

Introduction To Prototypes

“Using Prototypical Objects to Implement Shared Behavior in OO Systems“
slide-4
SLIDE 4 Dynamic Languages Day

Schedule

Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency References
slide-5
SLIDE 5 Dynamic Languages Day

Important Features of PBLs (1/3)

Three ways to create new objects Creation ex-nihilo Extension Cloning a prototype

slide-6
SLIDE 6 Dynamic Languages Day

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
t e x t
  • f
  • r
i g i n a l r e c e i v e r self x 100 a Pen at (100,200) delegates to searching... y 200 *draw a prototypical Pen at (50,200) x 50 searching...

draw

LOGO example
slide-7
SLIDE 7 Dynamic Languages Day

Important 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 self
slide-8
SLIDE 8 Dynamic Languages Day

Schedule

Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency References
slide-9
SLIDE 9 Dynamic Languages Day

History 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 today
slide-10
SLIDE 10 Dynamic Languages Day

Schedule

Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency References
slide-11
SLIDE 11 Dynamic Languages Day

Self’s Basics

Visual exploratory programming environment Desktop An object Input An object Trash
slide-12
SLIDE 12 Dynamic Languages Day

Self’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 slots
slide-13
SLIDE 13 Dynamic Languages Day

Self’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-down
slide-14
SLIDE 14 Dynamic Languages Day

Self’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 200

Convention

slide-15
SLIDE 15 Dynamic Languages Day

Self’s Basics

Maps transparently group objects x y 50 200 prototypical Pen a Pen copy 100 200 a Pen copy 20 30

Clone family

  • ffset
  • ffset
Map for Pen
slide-16
SLIDE 16 Dynamic Languages Day

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 draw
slide-17
SLIDE 17 Dynamic Languages Day

Self’s Basics

Multiple inheritance Traits MovingTurtle a Turtle at (50,200) with heading 90 x y 50 heading 90 forward 200 Traits DrawingTurtle draw backward
slide-18
SLIDE 18 Dynamic Languages Day

Schedule

Introduction to prototypes Important features of PBLs History of Self Self’s basics The power of Self Efficiency References
slide-19
SLIDE 19 Dynamic Languages Day

The 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 ...
slide-20
SLIDE 20 Dynamic Languages Day

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)
slide-21
SLIDE 21 Dynamic Languages Day

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: ?
slide-22
SLIDE 22 Dynamic Languages Day

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: ?
slide-23
SLIDE 23 Dynamic Languages Day

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 call

Six 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.)
slide-24
SLIDE 24 Dynamic Languages Day

Schedule

Introduction to prototypes Important features of PBLs History of Self Self’s character The power of Self Efficiency References
slide-25
SLIDE 25 Dynamic Languages Day

Efficiency

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 C
slide-26
SLIDE 26 Dynamic Languages Day

Schedule

Introduction to prototypes Important features of PBLs History of Self Self’s character The power of Self Efficiency References
slide-27
SLIDE 27 Dynamic Languages Day

References

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 /manuals
slide-28
SLIDE 28 Dynamic Languages Day

References

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ölzle
slide-29
SLIDE 29 Dynamic Languages Day

Questions

???

slide-30
SLIDE 30 Dynamic Languages Day
slide-31
SLIDE 31 Dynamic Languages Day