SlideShare a Scribd company logo
Modular Stateful
Traits in Pharo
Pablo Tesone
IMT - Lille-Douai / RMod INRIA
Traits
• We have duplicated
behaviour.

• Present in different
hierarchies. 

• Inheritance is not enough
!2
Person FileReference Operation
logModification
logCreation
...
Employee
logModification
logCreation
...
External
Resource logModification
logCreation
...
Sale
Traits (2)
• Reuse of behaviour

• Share behaviour outside the
hierarchy of classes.

• Reduce the duplication of
code.

• Manual resolution of conflicts.

• Not affecting the subclassing.
!3
logModification
logCreation
TAudit
<<uses>>
Employee
External
Resource
Sale
<<uses>>
<<uses>>
fullName
TNamed
<<uses>>
Some Implementation
Details
• Traits are flattened.

• Classes have copy of
the methods

• Handled by the traits
implementation… not
by the programmer.

• Transparent to the
Runtime
!4
...
Employee
...
logModification
logCreation
...
...
External
Resource
...
logModification
logCreation
...
...
Sale
...
logModification
logCreation
...
logModification
logCreation
TAudit
<<uses>>
<<uses>>
<<uses>>
But not perfect…
• Only can interact with
the instance through
messages.

• Needs of glue code
(usually accessors).

• Cannot define
instance variables
(slots)
!5
modification
creation
surname
name
...
Employee
modificationTime
modifiactionTime:
creationTime
creationTime:
surname
surname:
name
name:
modification
creation
...
External
Resource
modificationTime
modifiactionTime:
creationTime
creationTime:
...
modification
creation
...
Sale
modificationTime
modifiactionTime:
creationTime
creationTime:
...
logModification
logCreation
TAudit
<<uses>>
<<uses>>
<<uses>>
Stateful Traits
• Reuse of slots.

• Improving the
Initialisation

• We reduce the glue
code.

• Adding new operations
to handle conflicts.
!6
initializeTrait
logModification
TAudit
creation
modification
surname
name
...
Employee
surname
surname:
name
name:
...
External Resource
...
...
Sale
...
<<uses>>
<<uses>>
<<uses>>
Stateful Traits (2)
• Flattened Methods.

• Flattened Slots.

• Everything is compiled
correctly.

• Methods defined in a
trait accesses slots
defined in it directly.
!7
initializeTrait
logModification
TAudit
creation
modification
...
creation
modification
...
Employee
...
initializeTrait
logModification
...
...
creation
modification
...
External Resource
...
initializeTrait
logModification
...
...
creation
modification
...
Sale
...
initializeTrait
logModification
...
<<uses>>
<<uses>>
<<uses>>
Initialisation of instances
• Traited classes have
another initialisation
method.

• Perform the
initialisation of all the
traits.

• Generated if missed by
the traits mechanism.
!8
initializeTrait
logModification
TAudit
creation
modification
...
Employee
initialize
initializeTrait
initializeTAudit
initializeTWithRol
...
External Resource
initializeTrait
initialize
...
Sale
initializeTrait
initialize
<<uses>>
<<uses>>
<<uses>>
initializeTrait
rol
rol:
TWithRol
rol
<<uses>>
Initialisation of instances
!9
initializeTrait
logModification
TAudit
creation
modification
...
Employee
initialize
initializeTrait
initializeTAudit
initializeTWithRol
...
External Resource
initializeTrait
initialize
...
Sale
initializeTrait
initialize
<<uses>>
<<uses>>
<<uses>>
initializeTrait
rol
rol:
TWithRol
rol
<<uses>>
Sale >> initialize
super initialize.
self initializeTrait
Employee >> initialize
super initialize.
self initializeTrait
Employee >> initializeTrait
self initializeTWithRol.
self initializeTAudit
New Trait Composition
Operations
!10
• Alias Slot

• Remove Slot

• Merge Slots
Adding Slots brings new
conflicts.
!11
That’s not
new!!! Kill him!!
Also Fix other problems
!12
Pharo 6 Traits
Monolithic Impl.
Not Extensible
Limited Polymorphic w/classes
Modular Implementation
!13
• The kernel does not know nothing about
traits.

• They are loaded after.

• Reducing Codintional Code.
Modular Implementation
!14
Behavior >> includesBehavior: aClass
self isTrait ifTrue: [ ^false ].
^self == aClass or:[self inheritsFrom: aClass]
Behavior >> includesBehavior: aClass
^self == aClass or:[self inheritsFrom: aClass]
Trait >> includesBehavior: aClass
^false
Pharo 6
Pharo 7
Solved by Polymorphism
!15
Object Object class
Metaclass
Employee
Employee
Class
Traited
Metaclass
TAudit
<<uses>>
Audit
classSide
TTraitedClass
<<uses>> <<uses>>
Class
Kernel
Traits
Library
Polymorphism w/Classes
• The traits are traited
classes….. 

• But you cannot instantiate
them.

• We only provide the different
behaviour.

• Simplifies the tools
!16
Class Class class
Metaclass
Trait Trait Class
TAudit
:nil
TAudit
classSide
Metaclass
forTraits
TTraitedClass
TraitedMetaclass
Extensible Algebra
• We need the algebra to solve conflicts.

• New operations to handle slots:

• Rename

• Remove

• Alias

• Also the algebra easily extensible.
!17
Trait
Composition
Empty
Composition
Sequence
AliasMethod
.....
Trait
Composition
Remove
Slot
Rename
Slot
Merge
Slot
.....
Extensible Class Builder
• The class building process has been modified. Allowing
external extensions.

• All the creation of classes with traits are extension
methods.
!18
Shift
ClassBuilder
Default
Builder
Enhancer
compileMethodsFor: aBuilder
configureClass: newClass superclass: superclass
withLayoutType: layoutType slots: slots
afterMethodCompiled: aBuilder
TraitBuilderEnhancer
Does it scale?
• The methods and slots are flattened

• The slots are compiled in the target class.

• The initialisation code is chained.

• During runtime, there is no difference.

• 100 % Backward compatible.

• No VM Changes or needed support.
!19
Bonus: simplification of
MetaObject - Protocol
• Same MOP with classes.

• Classes, Traits (whatever) are only source of slots and methods.

• Better API for selectors, localSelectors and slots and localSlots.

• Simplifying the tools.

• System Traits deprecated (TClass, TBehavior, …)

• Still in progress…. so many tools to update.
!20
For the same price…. (?)
!21
Lines 22,606 15 %
Methods 2,897 21 %
Bootstrap
Process

5 min 30 %
Overall Pharo
Build
4 min 20 %
Kernel Reduction
Lines 6,557
Affected Packages 89
Tool Simplification
!22
Thanks!!!
Conclusion
• Stateful Traits!

• Modular Solution (faster bootstrap, you can
avoid it).

• Extensible

• Simpler MOP / Polymorphism with classes.

• Same performance!

• 100% Backward Compatible

More Related Content

Similar to Stateful traits in Pharo

C,s&s
C,s&sC,s&s
C,s&s
sid6376
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
Marcus Denker
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
Pharo
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Yasuko Ohba
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
juanvazquezslides
 
Java class 1
Java class 1Java class 1
Java class 1
Edureka!
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best Practices
David Keener
 
Introduction to ML.NET
Introduction to ML.NETIntroduction to ML.NET
Introduction to ML.NET
Marco Parenzan
 
Ruby On Rails Pitfalls
Ruby On Rails PitfallsRuby On Rails Pitfalls
Ruby On Rails Pitfalls
Robin Lu
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
Eugenio Lentini
 
C++ Online Training
C++ Online TrainingC++ Online Training
C++ Online Training
Srihitha Technologies
 
An Introduction to SPL, the Standard PHP Library
An Introduction to SPL, the Standard PHP LibraryAn Introduction to SPL, the Standard PHP Library
An Introduction to SPL, the Standard PHP Library
Robin Fernandes
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
Amr Abd El Latief
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
Khizar40
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
Woxa Technologies
 
Herding a Cat with Antlers - Catalyst 5.80
Herding a Cat with Antlers - Catalyst 5.80Herding a Cat with Antlers - Catalyst 5.80
Herding a Cat with Antlers - Catalyst 5.80
Tomas Doran
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Return on Intelligence
 
Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013
rivierarb
 

Similar to Stateful traits in Pharo (20)

C,s&s
C,s&sC,s&s
C,s&s
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
 
Java class 1
Java class 1Java class 1
Java class 1
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best Practices
 
Introduction to ML.NET
Introduction to ML.NETIntroduction to ML.NET
Introduction to ML.NET
 
Ruby On Rails Pitfalls
Ruby On Rails PitfallsRuby On Rails Pitfalls
Ruby On Rails Pitfalls
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
C++ Online Training
C++ Online TrainingC++ Online Training
C++ Online Training
 
An Introduction to SPL, the Standard PHP Library
An Introduction to SPL, the Standard PHP LibraryAn Introduction to SPL, the Standard PHP Library
An Introduction to SPL, the Standard PHP Library
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 
java training faridabad
java training faridabadjava training faridabad
java training faridabad
 
Herding a Cat with Antlers - Catalyst 5.80
Herding a Cat with Antlers - Catalyst 5.80Herding a Cat with Antlers - Catalyst 5.80
Herding a Cat with Antlers - Catalyst 5.80
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013
 

More from 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 programming
ESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
ESUG
 
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
ESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
ESUG
 
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 results
ESUG
 
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
ESUG
 
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
ESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
ESUG
 
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
ESUG
 
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
ESUG
 
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
ESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
ESUG
 
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
ESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
ESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
ESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
ESUG
 
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
ESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
ESUG
 
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
ESUG
 

More from 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
 

Recently uploaded

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 

Recently uploaded (20)

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 

Stateful traits in Pharo

  • 1. Modular Stateful Traits in Pharo Pablo Tesone IMT - Lille-Douai / RMod INRIA
  • 2. Traits • We have duplicated behaviour. • Present in different hierarchies. • Inheritance is not enough !2 Person FileReference Operation logModification logCreation ... Employee logModification logCreation ... External Resource logModification logCreation ... Sale
  • 3. Traits (2) • Reuse of behaviour • Share behaviour outside the hierarchy of classes. • Reduce the duplication of code. • Manual resolution of conflicts. • Not affecting the subclassing. !3 logModification logCreation TAudit <<uses>> Employee External Resource Sale <<uses>> <<uses>> fullName TNamed <<uses>>
  • 4. Some Implementation Details • Traits are flattened. • Classes have copy of the methods • Handled by the traits implementation… not by the programmer. • Transparent to the Runtime !4 ... Employee ... logModification logCreation ... ... External Resource ... logModification logCreation ... ... Sale ... logModification logCreation ... logModification logCreation TAudit <<uses>> <<uses>> <<uses>>
  • 5. But not perfect… • Only can interact with the instance through messages. • Needs of glue code (usually accessors). • Cannot define instance variables (slots) !5 modification creation surname name ... Employee modificationTime modifiactionTime: creationTime creationTime: surname surname: name name: modification creation ... External Resource modificationTime modifiactionTime: creationTime creationTime: ... modification creation ... Sale modificationTime modifiactionTime: creationTime creationTime: ... logModification logCreation TAudit <<uses>> <<uses>> <<uses>>
  • 6. Stateful Traits • Reuse of slots. • Improving the Initialisation • We reduce the glue code. • Adding new operations to handle conflicts. !6 initializeTrait logModification TAudit creation modification surname name ... Employee surname surname: name name: ... External Resource ... ... Sale ... <<uses>> <<uses>> <<uses>>
  • 7. Stateful Traits (2) • Flattened Methods. • Flattened Slots. • Everything is compiled correctly. • Methods defined in a trait accesses slots defined in it directly. !7 initializeTrait logModification TAudit creation modification ... creation modification ... Employee ... initializeTrait logModification ... ... creation modification ... External Resource ... initializeTrait logModification ... ... creation modification ... Sale ... initializeTrait logModification ... <<uses>> <<uses>> <<uses>>
  • 8. Initialisation of instances • Traited classes have another initialisation method. • Perform the initialisation of all the traits. • Generated if missed by the traits mechanism. !8 initializeTrait logModification TAudit creation modification ... Employee initialize initializeTrait initializeTAudit initializeTWithRol ... External Resource initializeTrait initialize ... Sale initializeTrait initialize <<uses>> <<uses>> <<uses>> initializeTrait rol rol: TWithRol rol <<uses>>
  • 9. Initialisation of instances !9 initializeTrait logModification TAudit creation modification ... Employee initialize initializeTrait initializeTAudit initializeTWithRol ... External Resource initializeTrait initialize ... Sale initializeTrait initialize <<uses>> <<uses>> <<uses>> initializeTrait rol rol: TWithRol rol <<uses>> Sale >> initialize super initialize. self initializeTrait Employee >> initialize super initialize. self initializeTrait Employee >> initializeTrait self initializeTWithRol. self initializeTAudit
  • 10. New Trait Composition Operations !10 • Alias Slot • Remove Slot • Merge Slots Adding Slots brings new conflicts.
  • 12. Also Fix other problems !12 Pharo 6 Traits Monolithic Impl. Not Extensible Limited Polymorphic w/classes
  • 13. Modular Implementation !13 • The kernel does not know nothing about traits. • They are loaded after. • Reducing Codintional Code.
  • 14. Modular Implementation !14 Behavior >> includesBehavior: aClass self isTrait ifTrue: [ ^false ]. ^self == aClass or:[self inheritsFrom: aClass] Behavior >> includesBehavior: aClass ^self == aClass or:[self inheritsFrom: aClass] Trait >> includesBehavior: aClass ^false Pharo 6 Pharo 7
  • 15. Solved by Polymorphism !15 Object Object class Metaclass Employee Employee Class Traited Metaclass TAudit <<uses>> Audit classSide TTraitedClass <<uses>> <<uses>> Class Kernel Traits Library
  • 16. Polymorphism w/Classes • The traits are traited classes….. • But you cannot instantiate them. • We only provide the different behaviour. • Simplifies the tools !16 Class Class class Metaclass Trait Trait Class TAudit :nil TAudit classSide Metaclass forTraits TTraitedClass TraitedMetaclass
  • 17. Extensible Algebra • We need the algebra to solve conflicts. • New operations to handle slots: • Rename • Remove • Alias • Also the algebra easily extensible. !17 Trait Composition Empty Composition Sequence AliasMethod ..... Trait Composition Remove Slot Rename Slot Merge Slot .....
  • 18. Extensible Class Builder • The class building process has been modified. Allowing external extensions. • All the creation of classes with traits are extension methods. !18 Shift ClassBuilder Default Builder Enhancer compileMethodsFor: aBuilder configureClass: newClass superclass: superclass withLayoutType: layoutType slots: slots afterMethodCompiled: aBuilder TraitBuilderEnhancer
  • 19. Does it scale? • The methods and slots are flattened • The slots are compiled in the target class. • The initialisation code is chained. • During runtime, there is no difference. • 100 % Backward compatible. • No VM Changes or needed support. !19
  • 20. Bonus: simplification of MetaObject - Protocol • Same MOP with classes. • Classes, Traits (whatever) are only source of slots and methods. • Better API for selectors, localSelectors and slots and localSlots. • Simplifying the tools. • System Traits deprecated (TClass, TBehavior, …) • Still in progress…. so many tools to update. !20
  • 21. For the same price…. (?) !21 Lines 22,606 15 % Methods 2,897 21 % Bootstrap Process 5 min 30 % Overall Pharo Build 4 min 20 % Kernel Reduction Lines 6,557 Affected Packages 89 Tool Simplification
  • 22. !22 Thanks!!! Conclusion • Stateful Traits! • Modular Solution (faster bootstrap, you can avoid it). • Extensible • Simpler MOP / Polymorphism with classes. • Same performance! • 100% Backward Compatible