SlideShare uma empresa Scribd logo
1 de 44
Baixar para ler offline
Prototypes in Pharo
Pavel Krivanek, Inria Nord Europe, RMoD
Prototype­based programming
● prototype: a typical member
used to represent a family or
a category of objects
● shared behavior using
delegation
● JavaScript, Lua, REBOL, Ioke…
● Self (first)
● 1986 Xerox PARC (David Ungar, Randall Smith)
● Standford University, Sun Microsystems (1990)
● slow progress since 1995, latest release May 2017
http://www.selflanguage.org/
How can we improve Smalltalk?
Let’s make it even simpler!
● prototype-based Smalltalk
● no classes, no metaclasses
● more focused on objects
● more Smalltalkish than Smalltalk
● only one keyword
● no symbols
● uniform messages and variables
● multiple dynamic inheritance
● namespaces
● modules
● full closures
● total object encapsulation
● was faster (2x)
Objects: composition of slots
● named references
– data slots (read-only / read-write)
– methods
– argument slots
– parent slots (read-only /read-write)
– auxiliary (unnamed slots, unnamed parent slots…)
Delegation
DEMO
Prototypes and traits
Prototypes and traits
Interesting syntax changes
● self-sends without self
● ifTrue:False:
● binary messages
1+2*3 must be (1+2)*3 or 1+(2*3)
● no symbols (canonical/mutable strings)
● implicit return value of methods
● literals for objects
● temporary variables, arguments
● 0-based indexes, C-like strings escaping
Method activation
Method activation
Method activation
Method activation
Delegation
mul: arg
parent*
a 3
x 2
:self*
:arg
(arg * a) pushSelf
send arg
pushSelf
send a
send *
returnTop
Delegation
mul: arg
parent*
a 3
x 2
:self*
:arg
(arg * a) pushSelf
send arg
pushSelf
send a
send *
returnTop
:self*
:arg
(arg * a) pushSelf
send arg
pushSelf
send a
send *
returnTop
(clone)
mul: x
Blocks
parent*
(lexicalParent)
value
(parent*)
(a + b) pushSelf
send a
pushSelf
send b
send +
returnTop
traits block
enclosing method's
activation object
block
block method
Blocks
whileTrue …
:self*
literal1
([x+y] value) pushSelf
send literal1
send value
returnTop
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
Blocks
whileTrue …
:self*
literal1
([x+y] value) pushSelf
send literal1
send value
returnTop
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
:self*
literal1
([y+y] value) pushSelf
send literal1
send value
returnTop
(clone) doSomething
Blocks
whileTrue …
:self*
literal1
([x+y] value) pushSelf
send literal1
send value
returnTop
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
:self*
literal1
([y+y] value) pushSelf
send literal1
send value
returnTop
(clone) doSomething
parent*
(lexicalParent)
value
(clone) block expression
evaluated
Blocks
whileTrue …
:self*
literal1
([x+y] value) pushSelf
send literal1
send value
returnTop
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
:self*
literal1
([y+y] value) pushSelf
send literal1
send value
returnTop
(clone) doSomething
parent*
(lexicalParent)
value
(parent*)
(x + y) pushSelf
send x
pushSelf
send y
send +
returnTop
(clone)
value
Embedded blocks
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
whileTrue …
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value:
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
4
Embedded blocks
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
whileTrue …
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value:
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
4
Embedded blocks
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
whileTrue …
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value:
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
4
Embedded blocks
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
(parent*)
:arg
(arg + 1) pushSelf
send arg
pushSelf
send literal3
send +
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
:self*
literal1
literal2
literal3 1
([x+([:arg | arg +1] value: y)] value) pushSelf
send literal1
send value
returnTop
whileTrue …
x 3
y 4
doSomething
traits block
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value
parent*
(lexicalParent)
value:
parent*
(lexicalParent)
value:
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
(parent*)
x+([:arg | arg+1] value: y) pushSelf
send x
pushSelf
send y
pushSelf
send literal2
send value:
send +
returnTop
value:
4
Prototypes in Smalltalk
● Several attempts (System-Prototypes, Prototypes)
● possible issues:
– memory inefficiency (dictionaries, associations)
– slow (DNU processing)
– limited delegation
– self sends
– tools support
Russel Allen’s dark magic (2005)
● create instance of Behavior (parent)
● set its superclass to Behavior
● create prototype as instance of the
parent
● clone instance variables of the
parent into the prototype
(superclass, method dict, format)
● parent gets identity of the prototype
● extend methods dictionary from
Prototype (addSlot:…)
Russel Allen’s dark magic (2005)
● create instance of Behavior (parent)
● set its superclass to Behavior
● create prototype as instance of the
parent
● clone instance variables of the
parent into the prototype
(superclass, method dict, format)
● parent gets identity of the prototype
● extend methods dictionary from
Prototype (addSlot:…)
→ the object is its own instance
Marvin
● objects as arrays
● no associations
● nil as separators
– parent slots
– methods
– data slots
– indexed content
Marvin
● Delegation implemented in VM
– Depth First Search (unlike Self)
– easy in that time
● Follow the Smalltalk infrastructure
– Smalltalk blocks
– Symbols
Marvin
● own syntax (SmaCC)
● mix of Self and Smalltalk
| p1 |
p1: (|
parent* = (|
parent* = (|
a = ( ^a ).
b = ‘symbol’ |).
a = ( resend.a ) |).
a = (|
a = 3.
b = 4 |).
method = ( resend.a a ) |).
p1 method
Self:
| p1 |
p1: (|
parent* = (|
parent* = (|
a = { ^a }.
b = #symbol |).
a = { ^resend a } |).
a = (|
a = 3.
b = 4 |).
method = { ^resend a a } |).
p1 method
Marvin:
current Marvin
● Delegation based on DNU
● Easier combination with regular objects
● Indexed content at the beginning
– Indexed access to inst. variables in CM
● Smalltalk objects injection
https://github.com/pavel-krivanek/Marvin
Objects injection
objectToExtend := Date today.
Objects injection
objectToExtend := Date today.
parent := MarvinPrototype new.
parent _AddMethod: 'suffix ^ self suffixString asUppercase'.
parent _AddReadSlot: #suffixString value: '_suffix'.
Objects injection
objectToExtend := Date today.
parent := MarvinPrototype new.
parent _AddMethod: 'suffix ^ self suffixString asUppercase'.
parent _AddReadSlot: #suffixString value: '_suffix'.
object := MarvinPrototype new.
object _AddParentSlot: #parent value: parent.
object _AddMethod: 'dayOfWeekName
^ super dayOfWeekName, self suffix'.
suffixString '_suffix’
suffix ^ self suffixString asUppercase
parent*
dayOfWeekName ^ super dayOfWeekName, self suffix
Objects injection
suffixString '_suffix’
suffix ^ self suffixString asUppercase
Date
parent*
class*
dayOfWeekName ^ super dayOfWeekName, self suffix
Date today
(instance variables)
objectToExtend := Date today.
parent := MarvinPrototype new.
parent _AddMethod: 'suffix ^ self suffixString asUppercase'.
parent _AddReadSlot: #suffixString value: '_suffix'.
object := MarvinPrototype new.
object _AddParentSlot: #parent value: parent.
object _AddMethod: 'dayOfWeekName
^ super dayOfWeekName, self suffix'.
object _Inject: objectToExtend.
object dayOfWeekName >>> 'Thursday_SUFFIX'
Why Self
is not more widely known and used?
What about Smalltalkers?
Self disadvantages
● lost commercial support (Sun)
● complicated VM
● platforms (no Windows VM, late Linux,
32-bits only)
● Morphic, UI, tools (outliners)
● Documentation
● Community
788x50844
Self disadvantages
Does it remove from Smalltalk things that 
make people productive?
Easy to loose control?
power of simplicity
under the hood
Prototypes in Pharo

Mais conteúdo relacionado

Mais procurados (19)

The Arrow Library in Kotlin
The Arrow Library in KotlinThe Arrow Library in Kotlin
The Arrow Library in Kotlin
 
2.1 Recap From Day One
2.1 Recap From Day One2.1 Recap From Day One
2.1 Recap From Day One
 
Proposals for new function in Java SE 9 and beyond
Proposals for new function in Java SE 9 and beyondProposals for new function in Java SE 9 and beyond
Proposals for new function in Java SE 9 and beyond
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
All about scala
All about scalaAll about scala
All about scala
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Cats in Scala
Cats in ScalaCats in Scala
Cats in Scala
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Introductory Clojure Presentation
Introductory Clojure PresentationIntroductory Clojure Presentation
Introductory Clojure Presentation
 
Scala
ScalaScala
Scala
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
 
01. haskell introduction
01. haskell introduction01. haskell introduction
01. haskell introduction
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
 
Python in 90 minutes
Python in 90 minutesPython in 90 minutes
Python in 90 minutes
 
Generics
GenericsGenerics
Generics
 
Java Day-6
Java Day-6Java Day-6
Java Day-6
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Java Day-4
Java Day-4Java Day-4
Java Day-4
 

Semelhante a Prototypes in Pharo

Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Jesper Kamstrup Linnet
 
Scala for Java Developers
Scala for Java DevelopersScala for Java Developers
Scala for Java DevelopersMartin Ockajak
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldWerner Hofstra
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersMiles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersSkills Matter
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersMiles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersMiles Sabin
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
Turtle Graphics in Groovy
Turtle Graphics in GroovyTurtle Graphics in Groovy
Turtle Graphics in GroovyJim Driscoll
 
Introductiontoprogramminginscala
IntroductiontoprogramminginscalaIntroductiontoprogramminginscala
IntroductiontoprogramminginscalaAmuhinda Hungai
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitTomer Gabel
 
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...Andrew Phillips
 
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Andrew Phillips
 

Semelhante a Prototypes in Pharo (20)

Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Python to scala
Python to scalaPython to scala
Python to scala
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
Scala for Java Developers
Scala for Java DevelopersScala for Java Developers
Scala for Java Developers
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Turtle Graphics in Groovy
Turtle Graphics in GroovyTurtle Graphics in Groovy
Turtle Graphics in Groovy
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Introductiontoprogramminginscala
IntroductiontoprogramminginscalaIntroductiontoprogramminginscala
Introductiontoprogramminginscala
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
 
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
 
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
Scala: A brief tutorial
Scala: A brief tutorialScala: A brief tutorial
Scala: A brief tutorial
 

Mais de ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsESUG
 

Mais de ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Último

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

Prototypes in Pharo

  • 2. Prototype­based programming ● prototype: a typical member used to represent a family or a category of objects ● shared behavior using delegation ● JavaScript, Lua, REBOL, Ioke… ● Self (first)
  • 3. ● 1986 Xerox PARC (David Ungar, Randall Smith) ● Standford University, Sun Microsystems (1990) ● slow progress since 1995, latest release May 2017 http://www.selflanguage.org/
  • 4.
  • 5.
  • 7. ● prototype-based Smalltalk ● no classes, no metaclasses ● more focused on objects ● more Smalltalkish than Smalltalk ● only one keyword ● no symbols ● uniform messages and variables
  • 8. ● multiple dynamic inheritance ● namespaces ● modules ● full closures ● total object encapsulation ● was faster (2x)
  • 9. Objects: composition of slots ● named references – data slots (read-only / read-write) – methods – argument slots – parent slots (read-only /read-write) – auxiliary (unnamed slots, unnamed parent slots…)
  • 13. Interesting syntax changes ● self-sends without self ● ifTrue:False: ● binary messages 1+2*3 must be (1+2)*3 or 1+(2*3) ● no symbols (canonical/mutable strings) ● implicit return value of methods ● literals for objects ● temporary variables, arguments ● 0-based indexes, C-like strings escaping
  • 18. Delegation mul: arg parent* a 3 x 2 :self* :arg (arg * a) pushSelf send arg pushSelf send a send * returnTop
  • 19. Delegation mul: arg parent* a 3 x 2 :self* :arg (arg * a) pushSelf send arg pushSelf send a send * returnTop :self* :arg (arg * a) pushSelf send arg pushSelf send a send * returnTop (clone) mul: x
  • 20. Blocks parent* (lexicalParent) value (parent*) (a + b) pushSelf send a pushSelf send b send + returnTop traits block enclosing method's activation object block block method
  • 21. Blocks whileTrue … :self* literal1 ([x+y] value) pushSelf send literal1 send value returnTop (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop x 3 y 4 doSomething traits block parent* (lexicalParent) value
  • 22. Blocks whileTrue … :self* literal1 ([x+y] value) pushSelf send literal1 send value returnTop (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop x 3 y 4 doSomething traits block parent* (lexicalParent) value :self* literal1 ([y+y] value) pushSelf send literal1 send value returnTop (clone) doSomething
  • 23. Blocks whileTrue … :self* literal1 ([x+y] value) pushSelf send literal1 send value returnTop (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop x 3 y 4 doSomething traits block parent* (lexicalParent) value :self* literal1 ([y+y] value) pushSelf send literal1 send value returnTop (clone) doSomething parent* (lexicalParent) value (clone) block expression evaluated
  • 24. Blocks whileTrue … :self* literal1 ([x+y] value) pushSelf send literal1 send value returnTop (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop x 3 y 4 doSomething traits block parent* (lexicalParent) value :self* literal1 ([y+y] value) pushSelf send literal1 send value returnTop (clone) doSomething parent* (lexicalParent) value (parent*) (x + y) pushSelf send x pushSelf send y send + returnTop (clone) value
  • 25. Embedded blocks (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop whileTrue … x 3 y 4 doSomething traits block parent* (lexicalParent) value parent* (lexicalParent) value: (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop 4
  • 26. Embedded blocks (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop whileTrue … x 3 y 4 doSomething traits block parent* (lexicalParent) value parent* (lexicalParent) value: (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop 4
  • 27. Embedded blocks (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop whileTrue … x 3 y 4 doSomething traits block parent* (lexicalParent) value parent* (lexicalParent) value parent* (lexicalParent) value: (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop 4
  • 28. Embedded blocks (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop (parent*) :arg (arg + 1) pushSelf send arg pushSelf send literal3 send + returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop :self* literal1 literal2 literal3 1 ([x+([:arg | arg +1] value: y)] value) pushSelf send literal1 send value returnTop whileTrue … x 3 y 4 doSomething traits block parent* (lexicalParent) value parent* (lexicalParent) value parent* (lexicalParent) value: parent* (lexicalParent) value: (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop (parent*) x+([:arg | arg+1] value: y) pushSelf send x pushSelf send y pushSelf send literal2 send value: send + returnTop value: 4
  • 29. Prototypes in Smalltalk ● Several attempts (System-Prototypes, Prototypes) ● possible issues: – memory inefficiency (dictionaries, associations) – slow (DNU processing) – limited delegation – self sends – tools support
  • 30. Russel Allen’s dark magic (2005) ● create instance of Behavior (parent) ● set its superclass to Behavior ● create prototype as instance of the parent ● clone instance variables of the parent into the prototype (superclass, method dict, format) ● parent gets identity of the prototype ● extend methods dictionary from Prototype (addSlot:…)
  • 31. Russel Allen’s dark magic (2005) ● create instance of Behavior (parent) ● set its superclass to Behavior ● create prototype as instance of the parent ● clone instance variables of the parent into the prototype (superclass, method dict, format) ● parent gets identity of the prototype ● extend methods dictionary from Prototype (addSlot:…) → the object is its own instance
  • 32. Marvin ● objects as arrays ● no associations ● nil as separators – parent slots – methods – data slots – indexed content
  • 33. Marvin ● Delegation implemented in VM – Depth First Search (unlike Self) – easy in that time ● Follow the Smalltalk infrastructure – Smalltalk blocks – Symbols
  • 34. Marvin ● own syntax (SmaCC) ● mix of Self and Smalltalk | p1 | p1: (| parent* = (| parent* = (| a = ( ^a ). b = ‘symbol’ |). a = ( resend.a ) |). a = (| a = 3. b = 4 |). method = ( resend.a a ) |). p1 method Self: | p1 | p1: (| parent* = (| parent* = (| a = { ^a }. b = #symbol |). a = { ^resend a } |). a = (| a = 3. b = 4 |). method = { ^resend a a } |). p1 method Marvin:
  • 35. current Marvin ● Delegation based on DNU ● Easier combination with regular objects ● Indexed content at the beginning – Indexed access to inst. variables in CM ● Smalltalk objects injection https://github.com/pavel-krivanek/Marvin
  • 37. Objects injection objectToExtend := Date today. parent := MarvinPrototype new. parent _AddMethod: 'suffix ^ self suffixString asUppercase'. parent _AddReadSlot: #suffixString value: '_suffix'.
  • 38. Objects injection objectToExtend := Date today. parent := MarvinPrototype new. parent _AddMethod: 'suffix ^ self suffixString asUppercase'. parent _AddReadSlot: #suffixString value: '_suffix'. object := MarvinPrototype new. object _AddParentSlot: #parent value: parent. object _AddMethod: 'dayOfWeekName ^ super dayOfWeekName, self suffix'. suffixString '_suffix’ suffix ^ self suffixString asUppercase parent* dayOfWeekName ^ super dayOfWeekName, self suffix
  • 39. Objects injection suffixString '_suffix’ suffix ^ self suffixString asUppercase Date parent* class* dayOfWeekName ^ super dayOfWeekName, self suffix Date today (instance variables) objectToExtend := Date today. parent := MarvinPrototype new. parent _AddMethod: 'suffix ^ self suffixString asUppercase'. parent _AddReadSlot: #suffixString value: '_suffix'. object := MarvinPrototype new. object _AddParentSlot: #parent value: parent. object _AddMethod: 'dayOfWeekName ^ super dayOfWeekName, self suffix'. object _Inject: objectToExtend. object dayOfWeekName >>> 'Thursday_SUFFIX'
  • 41. Self disadvantages ● lost commercial support (Sun) ● complicated VM ● platforms (no Windows VM, late Linux, 32-bits only) ● Morphic, UI, tools (outliners) ● Documentation ● Community 788x50844