SlideShare a Scribd company logo
Redesigning with Traits
The Nile Stream trait-based Library
Damien Cassou1 Stéphane Ducasse1 Roel Wuyts2
1LISTIC, University of Savoie, France
2IMEC, Leuven and Université Libre de Bruxelles
European Smalltalk User Group, 2007
Outline
Context
Traits
Problems
Streams
Nile
Implementation
Results
Conclusion
Further work
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 2 / 19
Context
Outline
Context
Traits
Problems
Streams
Nile
Implementation
Results
Conclusion
Further work
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 3 / 19
Context Traits
Traits Introduction
Traits
• group of reusable methods
• implemented and required methods
• conflict management
• implemented in Perl 6, Fortress, Scala, Smalltalk
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 4 / 19
Context Traits
Trait sample
>
>=
<=
between:and:
<
=
TMagnitude
<
=
...
String
<
=
...
Number
<
=
...
Date
• TMagnitude offers four methods and requires two
• A class uses traits and implements required methods
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 5 / 19
Context Problems
Problems
Observation
Never used to design framemorks/libraries from scratch
Questions
• ideal trait granularity?
• how much code reuse?
• trait or class?
• limits, constraints, problems?
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 6 / 19
Context Problems
Designing a New Trait-based Stream Library
Solution
• development of an adapted project
• choosing the stream library
Needs
• compatibility with ANSI Smalltalk
• compatibility with the current Squeak implementation
• speed efficient
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 7 / 19
Context Problems
Streams
Streams
Streams are used to read and write data sequentially in collections,
files and network sockets.
Reading
• next
• next:
• peek
Writing
• nextPut:
• nextPutAll:
• next:put:
Positioning
• position:
• reset
• setToEnd
Why streams ?
• naturally modeled using multiple inheritance
• existing implementations (some of them trait-based)
• complex library
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 8 / 19
Context Streams
Squeak Implementation
atEnd
close
contents
do:
flush
next
next:
next:put:
nextPut:
nextPutAll:
upToEnd
Stream
atEnd
contents
isEmpty
next:
peek
position
position:
reset
setToEnd
skip:
upTo:
upToEnd
collection
position
readLimit
Positionable
Stream
next
next:
nextPut:
size
upTo:
upToEnd
ReadStream
contents
flush
next
nextPut:
nextPutAll:
position:
reset
size
space
cr
writeLimit
WriteStream
contents
next
next:
ReadWriteStream
atEnd
close
flush
fullName
next
next:
nextPut:
nextPutAll:
peek
position
position:
reset
size
rwmode
name
fileID
buffer1
FileStream
• everything in the Stream class
• methods disabled
• reimplemented methods
• methods reactivated
• files inherit from collections
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 9 / 19
Context Streams
Schärli’s Refactoring
OOPSLA 2003
flush
close
TStreamCommon
contents:
last
originalContents
atEnd
isEmpty
position:
reset
resetContents
setToEnd
skip:
error:
position
privatePosition:
collection
collection:
readLimit
readLimit:
TStreamPositionable
position:
collection
collection:
readLimit:
TStreamReadWrite
Common
nextMatchFor:
upToEnd
do:
next:
atEnd
next
TStreamReadable
next
next:
peek
peekFor:
size
upTo:
upToEnd
position
collection
position:
readLimit:
skip:
TStreamReadable
Positionable nextPutAll: nextPut:
error:
TStreamWriteable
resetToStart
nextPut:
size
position
position:
skip:
collection
collection:
readLimit
readLimit:
writeLimit
writeLimit:
TStreamWriteable
Positionable
StreamTop
collection
position
readLimit
StreamPositionable
Stream
StreamReadStream
close
closed
contents
writeLimit
StreamReadWrite
Stream
-{#size}
writeLimit
StreamWriteStream
Only a refactoring
• no positioning
for files
• peek depends
on position and
collection
• . . .
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 10 / 19
Nile
Outline
Context
Traits
Problems
Streams
Nile
Implementation
Results
Conclusion
Further work
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 11 / 19
Nile Implementation
Nile overview
Core
Collection-based Streams
File-based Streams
Character writing
Decoders
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 12 / 19
Nile Implementation
Collection-based Streams
collection
position
ReadableCollectionStream collection
position
writeLimit
Writeable
CollectionStream
collection
position
writeLimit
ReadWriteCollectionStream
do:
nextMatchFor:
next:
peekFor:
skip:
skipTo:
upTo:
upToEnd
upToElementSatisfying:
atEnd
next
peek
outputCollectionClass
TGettableStream
atEnd
atStart
close
isEmpty
position:
reset
setToEnd
position
setPosition:
size
TPositionableStream
nextPutAll:
next:put:
print:
flush
nextPut:
TPuttableStream
contents
size
collection
setCollection:
TCollectionStream
nextPut:
size
writeLimit
writeLimit:
TWriteableCollection
Stream
-{#size}
Core
next
peek
skip:
outputCollectionClass
TReadableCollectionStream
• a trait per basic functionality
• traits for collections and one class for each original Squeak class
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 13 / 19
Nile Implementation
Other Implemented Libraries
Core
Collection-based Streams
File-based Streams
Character writing
Decoders
Other Implemented Libraries
Files file-based streams
Random random number generator
SharedQueue queue concurrent access
Decoder pipe system to chain streams (compression,
multiplexing. . . )
and many others. . .
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 14 / 19
Nile Results
New Design
Good Code Reuse
• good code reuse : 22 classes use TGettableStream
• important gain : TCharacterWriting requires implementing one
method to gain 8
Better Implementation
• 18% fewer methods
• 15% less byte-code
• not forced to use unwanted behavior
Better Performance
• faster execution
• traits don’t prevent optimization
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 15 / 19
Nile Results
Trait-related Problems Discovered
• interface pollution
• traits require accessors
• sometimes an extra getter or setter
• IDE support for traits needs improvement
• difficult to visualize and navigate
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 16 / 19
Conclusion
Outline
Context
Traits
Problems
Streams
Nile
Implementation
Results
Conclusion
Further work
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 17 / 19
Conclusion Further work
Further Work
• Having an equivalent implementation?
• much more entities (11 traits+classes compared to 4 classes in
Squeak)
• simplify using only read/write access?
• lot’s of ugly code in the original implementation
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 18 / 19
Conclusion Further work
Conclusion
• Context
• traits needed to be tested in a new project
• a stream library is a good project example
• Realized work
• existing implementation was analyzed
• new design was created
• efficient implementation
• problem analysis
• really improves the design
• needs further work
D. Cassou, S. Ducasse, R. Wuyts (Savoie, Bruxelles) Redesigning with Traits ESUG 2007 19 / 19

More Related Content

PDF
AIDA/Web 6.0 This is how the Web works!
PDF
Esug java
PDF
Inter-Language Reflection
PDF
The Sport BOF
PDF
Smalltalk-80 : hardware and software
PDF
Managing business processes with Smalltalk
PDF
Smalltalk Standards Project
PDF
Runtime Bytecode Transformation for Smalltalk
AIDA/Web 6.0 This is how the Web works!
Esug java
Inter-Language Reflection
The Sport BOF
Smalltalk-80 : hardware and software
Managing business processes with Smalltalk
Smalltalk Standards Project
Runtime Bytecode Transformation for Smalltalk

Similar to Redesigning with Traits (13)

PPT
Traits: A New Language Feature for PHP?
PDF
TI1220 Lecture 8: Traits & Type Parameterization
PDF
Understanding Continuous Design in F/OSS Projects
PPT
Stoop ed-class forreuse
PDF
Uniform and Safe Metaclass Composition
PDF
Six Myths and Paradoxes of Garbage Collection
PDF
Software Architecture: Principles, Patterns and Practices
PDF
OOP Intro in Ruby for NHRuby Feb 2010
KEY
Traits composition
PPT
Java Basics
PPT
Java basics
PDF
A Checklist for Design Reviews
Traits: A New Language Feature for PHP?
TI1220 Lecture 8: Traits & Type Parameterization
Understanding Continuous Design in F/OSS Projects
Stoop ed-class forreuse
Uniform and Safe Metaclass Composition
Six Myths and Paradoxes of Garbage Collection
Software Architecture: Principles, Patterns and Practices
OOP Intro in Ruby for NHRuby Feb 2010
Traits composition
Java Basics
Java basics
A Checklist for Design Reviews
Ad

More from ESUG (20)

PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
PDF
Directing Generative AI for Pharo Documentation
PDF
Even Lighter Than Lightweiht: Augmenting Type Inference with Primitive Heuris...
PDF
Composing and Performing Electronic Music on-the-Fly with Pharo and Coypu
PDF
Gamifying Agent-Based Models in Cormas: Towards the Playable Architecture for...
PDF
Analysing Python Machine Learning Notebooks with Moose
PDF
FASTTypeScript metamodel generation using FAST traits and TreeSitter project
PDF
Migrating Katalon Studio Tests to Playwright with Model Driven Engineering
PDF
Package-Aware Approach for Repository-Level Code Completion in Pharo
PDF
Evaluating Benchmark Quality: a Mutation-Testing- Based Methodology
PDF
An Analysis of Inline Method Refactoring
PDF
Identification of unnecessary object allocations using static escape analysis
PDF
Control flow-sensitive optimizations In the Druid Meta-Compiler
PDF
Clean Blocks (IWST 2025, Gdansk, Poland)
PDF
Encoding for Objects Matters (IWST 2025)
PDF
Challenges of Transpiling Smalltalk to JavaScript
PDF
Immersive experiences: what Pharo users do!
PDF
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
PDF
Cavrois - an Organic Window Management (ESUG 2025)
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
Micromaid: A simple Mermaid-like chart generator for Pharo
Directing Generative AI for Pharo Documentation
Even Lighter Than Lightweiht: Augmenting Type Inference with Primitive Heuris...
Composing and Performing Electronic Music on-the-Fly with Pharo and Coypu
Gamifying Agent-Based Models in Cormas: Towards the Playable Architecture for...
Analysing Python Machine Learning Notebooks with Moose
FASTTypeScript metamodel generation using FAST traits and TreeSitter project
Migrating Katalon Studio Tests to Playwright with Model Driven Engineering
Package-Aware Approach for Repository-Level Code Completion in Pharo
Evaluating Benchmark Quality: a Mutation-Testing- Based Methodology
An Analysis of Inline Method Refactoring
Identification of unnecessary object allocations using static escape analysis
Control flow-sensitive optimizations In the Druid Meta-Compiler
Clean Blocks (IWST 2025, Gdansk, Poland)
Encoding for Objects Matters (IWST 2025)
Challenges of Transpiling Smalltalk to JavaScript
Immersive experiences: what Pharo users do!
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
Cavrois - an Organic Window Management (ESUG 2025)
Ad

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation theory and applications.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
Teaching material agriculture food technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Big Data Technologies - Introduction.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
Building Integrated photovoltaic BIPV_UPV.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Programs and apps: productivity, graphics, security and other tools
Encapsulation theory and applications.pdf
Empathic Computing: Creating Shared Understanding
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Teaching material agriculture food technology
sap open course for s4hana steps from ECC to s4
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Unlocking AI with Model Context Protocol (MCP)
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25-Week II
Big Data Technologies - Introduction.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Per capita expenditure prediction using model stacking based on satellite ima...

Redesigning with Traits