SlideShare a Scribd company logo
Please, feel free to interrupt me at any time.
Do you use: Multiple Inheritance? Mixins?
Traits A Language Feature for PHP? Stefan Marr PHP Unconference Hamburg 26-27 April 2008
Agenda Introduction to Traits Traits Applied Traits for PHP: Trait versus Graft Roundup and Conclusion
Which problem is to be solved? Single inheritance Simple but not  expressive enough Leads to Code duplication Inappropriate  hierarchies
Traits Set of methods Possibly composed of other Traits Composition is unordered Composition operations Sum Exclusion Aliasing Can be flattened away
Whiteboard
TRAITS APPLIED Case Studies Illustrating Benefits of Traits
Use Case for Traits in a PHP Library ezcReflection enhances PHP Reflection API Adds XDoclet like annotations for PHP Enhances type hinting using PHPDoc type annotations Illustrates solution for code duplication problems
Refactoring ezcReflection with Traits original with Traits green parts are extracted to the Traits on the right-hand side, and will be removed from the classes
Case Study: java.io [6] Mature code base, in wide use java.io Library from Java 1.4.2 79 classes, 25000 lines of code Results 12 classes changed 30 duplicated methods removed 14 Traits introduces
from [6]
Case Study: Smalltalk Collection Classes [10] Problem: code reuse vs. conceptual categorization Unnecessary inheritance Code duplication Methods to high in hierarchy Conceptual shortcomings Results for core collection classes 23 classes changed,  12% less code, 19.4% less methods
Case Study: Smalltalk Collection Classes [10] Lessons Learned Traits simplify refactoring Very fine-grained traits Tools are important Traits enable to defer design of class hierarchy Improvements Uniformity, understandability, reuse
Check for Limitations Code duplication Inappropriate hierarchies Diamond problem Fragile hierarchies Lack of composition control     
TRAITS FOR PHP Trait versus Graft
What is a Graft? Stateful, non-breakable entity of reuse Derived from the Traits notion Proposed with RFC: Non Breakable Traits for PHP Why Graft? From  The Grafter's Handbook  by R.J. Garner
A Comparison Traits Purpose, reuse of behavior Features Stateless Flattenable Explicit conflict resolution Highly composable Notion Language-base Copy and Paste Grafts Purpose, reuse of modules smaller then classes Features Stateful Hides complexity Conflict avoidiance Strong encapsulation Notion Delegation with self-impersonation
Traits Syntax and Semantics trait  A { public function  small() { echo  'a' ; } public function  big()  { echo  'A' ; } abstract public function  doBFoo(); public function  doAFoo() { echo  'AFoo uses BFoo: ' ; $this ->doBFoo(); } } trait  B { public function s mall() { echo  'b' ; } public function  big()  { echo  'B' ; } public function  doBFoo() { echo  'B-FOO' ; } } class  Talker { use  A, B { B::small  instead  A::small,  A::big  instead  B::big, B::big  as  talk } } $talker  =  new  Talker(); $talker ->small();  // b  $talker ->big();  // A $talker ->talk();  // B $talker ->doAFoo();  // AFoo uses   // BFoo: B-FOO $talker ->doBFoo();  // B-FOO
Grafts Syntax and Semantics graft  Counter { private  $cnt = 0 ; public function  inc() { $this ->cnt++; } public function  reset() { $this ->cnt = -1; $this ->inc(); } } graft  DB { private  $db; public function  connect() { $this ->db = new FooDB( 'param' ); } public function  reset() { $this ->db->flush(); $this ->db = null; } public function  doFoo(){echo  'foo' ;} } class  MyPage { include  Counter { public  incCnt()  as  inc(); public  resetCnt()  as  reset(); } include  DB { public  connect(); public  reset(); } public function  inc() { /* next page */ } } $page  =  new  MyPage(); $page ->connect(); $page ->incCnt();  //($Countercnt == 1) $page ->resetCnt();  // $Countercnt = 0; $page ->inc();  // goto next page $page ->doFoo();  // FATAL ERROR
My Mental Image Traits Grafts
ROUNDUP AND CONCLUSION Trait Support, Discussion, Resume
Environments Supporting Traits Squeak: In standard distribution since 3.9 [11] Trait named: #TDrawing uses: {} draw ˆself drawOn: World canvas in: bounds bounds self requirement Object subclass: #Circle instanceVariableNames: ’’ traits: { TDrawing } ...
Environments Supporting Traits Scala: static-typed language running on JVM [7] trait  TDrawing { def  draw() : Any =  drawOn(World.canvas(), bounds) def  bounds() : Any } class  Circle  extends  TDrawing { ... }
Environments Supporting Traits Perl6: Flavor of Traits with states called Roles [12] role  TDrawing { method  draw() {    return  drawOn(World.canvas(),   bounds); } } class  Circle  does  TDrawing { ... }
Environments Supporting Traits Approaches for plain Java Using AspectJ [2] Utilizing an Eclipse Plugin [8]
Environments Supporting Traits Approaches for plain Java Using AspectJ [2] Utilizing an Eclipse Plugin [8]
Environments Supporting Traits C#: Prototype Implementation for Rotor [9] trait  TDrawing { public  Object draw() {    return  drawOn(World.canvas(),   this .bounds); } requires  {  public  Object bounds();  } } class  Circle { uses  { TDrawing } ... }
Resume Traits are a appropriate language construct to: Achive conceptual consistent class hierarchies Avoid code duplication Enhance class compositon capabilites Available for different languages Two different flavors proposed for PHP
Request for Comments Traits for PHP Version:  1.5 Date:  2008-03-06 Author:  Stefan Marr Wiki: http://wiki.php.net/rfc/traits reST: http://www.stefan-marr.de/rfc-traits-for-php.txt HTML: http://www.stefan-marr.de/artikel/rfc-traits-for-php.html Non Breakable Traits for PHP Version:  1.0 Date:  2008-02-29 Author:  Joshua Thompson Wiki:  http://wiki.php.net/rfc/nonbreakabletraits
Basic Literature Main Article about Traits  [3] S. DUCASSE, O. NIERSTRASZ, N. SCHÄRLI, R. WUYTS, AND A. P. BLACK,  Traits: A Mechanism for Fine-Grained Reuse , ACM Trans. Program. Lang. Syst., 28 (2006), pp. 331–388. Traits Extensions [1] A. BERGEL, S. DUCASSE, O. NIERSTRASZ, AND R. WUYTS,  Stateful Traits and their Formalization , Journal of Computer Languages, Systems and Structures, 34 (2007), pp. 83–108. [4] S. DUCASSE, R. WUYTS, A. BERGEL, AND O. NIERSTRASZ,  User-Changeable Visibility: Resolving Unanticipated Name Clashes in Traits , SIGPLAN Not., 42 (2007), pp. 171–190.
Literature [1] A. BERGEL, S. DUCASSE, O. NIERSTRASZ, AND R. WUYTS,  Stateful Traits and their Formalization , Journal of Computer Languages, Systems and Structures, 34 (2007), pp. 83–108. [2] S. DENIER,  Traits Programming with AspectJ , RSTI - L'objet, 11 (2005), pp. 69–86. [3] S. DUCASSE, O. NIERSTRASZ, N. SCHÄRLI, R. WUYTS, AND A. P. BLACK,  Traits: A Mechanism for Fine-Grained Reuse , ACM Trans. Program. Lang. Syst., 28 (2006), pp. 331–388. [4] S. DUCASSE, R. WUYTS, A. BERGEL, AND O. NIERSTRASZ,  User-Changeable Visibility: Resolving Unanticipated Name Clashes in Traits , SIGPLAN Not., 42 (2007), pp. 171–190. [5] S. MARR AND F. MENGE,  ezcReflection , SVN Repository, eZ Components, January 2008. http://svn.ez.no/svn/ezcomponents/experimental/Reflection. [6] E. R. MURPHY-HILL, P. J. QUITSLUND, AND A. P. BLACK,  Removing Duplication from java.io: a Case Study using Traits , in OOPSLA '05: Companion to the 20th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, New York, NY, USA, 2005, ACM, pp. 282–291.
Literature [7] PROGRAMMING METHODS LABORATORY,  Traits for Scala , Programming Language, Ecole Polytechnique Fédérale de Lausanne, 2006. http://www.scala-lang.org/intro/traits.html. [8] P. J. QUITSLUND, E. R. MURPHY-HILL, AND A. P. BLACK,  Supporting Java traits in Eclipse , in eclipse '04: Proceedings of the 2004 OOPSLA workshop on eclipse technology eXchange, New York, NY, USA, 2004, ACM, pp. 37–41. [9] S. REICHHART,  Traits in C# .  Video of Talk at Microsoft Research, September 2005. [10] N. SCHÄRLI,  Traits — Composing Classes from Behavioral Building Blocks , PhD thesis, University of Berne, Feb. 2005. [11] SOFTWARE COMPOSITION GROUP,  Traits for Squeak , Smalltalk VM, University of Berne, December 2006. http://www.iam.unibe.ch/ scg/Research/Traits/index.html. [12] L. WALL,  Apocalypse 12: Class Composition with Roles , tech. report, The Perl Foundation, 2004. http://www.perl.com/pub/a/2004/04/16/a12.html?page=11.
Any questions? Discussion What du you think? Traits vs. Grafts
TRAITS ENHANCED User-Changeable Visibility and Stateful Traits
User-Changeable Visibility Add flexibility to conflict handling Introduces “Trait private” methods Methods visibility changeable on composition
Stateless Traits Problem: stateless Traits are incomplete, not self-contained units of reuse Required state accessors bloat the interfaces Encapsulation is violated by public accessors Reuse, composition is hampered State access introduces fragility
Stateless Traits
Stateful Traits Solution requirements: Preserver faltening property Minimal and general approach Language independed Solution State is private to the Traits scope Client can request access under new private name Client can merge state
Stateful Traits

More Related Content

What's hot

Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
melbournepatterns
 
Domain specific languages and Scala
Domain specific languages and ScalaDomain specific languages and Scala
Domain specific languages and Scala
Filip Krikava
 
Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)
Ralf Laemmel
 
Representing and Reasoning with Modular Ontologies
Representing and Reasoning with Modular OntologiesRepresenting and Reasoning with Modular Ontologies
Representing and Reasoning with Modular Ontologies
Jie Bao
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
Nilesh Dalvi
 
Integration of Domain-Specific and Domain-Independent Ontologies for Colonosc...
Integration of Domain-Specific and Domain-Independent Ontologies for Colonosc...Integration of Domain-Specific and Domain-Independent Ontologies for Colonosc...
Integration of Domain-Specific and Domain-Independent Ontologies for Colonosc...
Jie Bao
 
Dart workshop
Dart workshopDart workshop
Dart workshop
Vishnu Suresh
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
246paa
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
J. C.
 
Reviewing OOP Design patterns
Reviewing OOP Design patternsReviewing OOP Design patterns
Reviewing OOP Design patterns
Olivier Bacs
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
Fridz Felisco
 
Chado introduction
Chado introductionChado introduction
Chado introduction
Chris Mungall
 
Chado-XML
Chado-XMLChado-XML
Chado-XML
Chris Mungall
 
Chado for evolutionary biology
Chado for evolutionary biologyChado for evolutionary biology
Chado for evolutionary biology
Chris Mungall
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#
Tomas Petricek
 
Little languages
Little languagesLittle languages
Little languages
Chris Laffra
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
Ajit Nayak
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
DINESH KUMAR ARIVARASAN
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in Dotty
Martin Odersky
 
Transformer Seq2Sqe Models: Concepts, Trends & Limitations (DLI)
Transformer Seq2Sqe Models: Concepts, Trends & Limitations (DLI)Transformer Seq2Sqe Models: Concepts, Trends & Limitations (DLI)
Transformer Seq2Sqe Models: Concepts, Trends & Limitations (DLI)
Deep Learning Italia
 

What's hot (20)

Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
Domain specific languages and Scala
Domain specific languages and ScalaDomain specific languages and Scala
Domain specific languages and Scala
 
Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)
 
Representing and Reasoning with Modular Ontologies
Representing and Reasoning with Modular OntologiesRepresenting and Reasoning with Modular Ontologies
Representing and Reasoning with Modular Ontologies
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
 
Integration of Domain-Specific and Domain-Independent Ontologies for Colonosc...
Integration of Domain-Specific and Domain-Independent Ontologies for Colonosc...Integration of Domain-Specific and Domain-Independent Ontologies for Colonosc...
Integration of Domain-Specific and Domain-Independent Ontologies for Colonosc...
 
Dart workshop
Dart workshopDart workshop
Dart workshop
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
 
Reviewing OOP Design patterns
Reviewing OOP Design patternsReviewing OOP Design patterns
Reviewing OOP Design patterns
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
 
Chado introduction
Chado introductionChado introduction
Chado introduction
 
Chado-XML
Chado-XMLChado-XML
Chado-XML
 
Chado for evolutionary biology
Chado for evolutionary biologyChado for evolutionary biology
Chado for evolutionary biology
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#
 
Little languages
Little languagesLittle languages
Little languages
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
 
Implementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in DottyImplementing Higher-Kinded Types in Dotty
Implementing Higher-Kinded Types in Dotty
 
Transformer Seq2Sqe Models: Concepts, Trends & Limitations (DLI)
Transformer Seq2Sqe Models: Concepts, Trends & Limitations (DLI)Transformer Seq2Sqe Models: Concepts, Trends & Limitations (DLI)
Transformer Seq2Sqe Models: Concepts, Trends & Limitations (DLI)
 

Similar to Traits: A New Language Feature for PHP?

Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
Guillaume Laforge
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
google
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
Daniel Egan
 
F# 101
F# 101F# 101
F# 101
Chris Alcock
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
dn
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
Peter Gfader
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
YLTO
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
Mark Menard
 
F# for functional enthusiasts
F# for functional enthusiastsF# for functional enthusiasts
F# for functional enthusiasts
Jack Fox
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
Puppet
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
YoungSu Son
 
Sparklis exploration et interrogation de points d'accès sparql par interactio...
Sparklis exploration et interrogation de points d'accès sparql par interactio...Sparklis exploration et interrogation de points d'accès sparql par interactio...
Sparklis exploration et interrogation de points d'accès sparql par interactio...
SemWebPro
 
Stay fresh
Stay freshStay fresh
Stay fresh
Ahmed Mohamed
 
The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
Alessandro Sanino
 
Xbase implementing specific domain language for java
Xbase  implementing specific domain language for javaXbase  implementing specific domain language for java
Xbase implementing specific domain language for java
Yash Patel
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible research
Andrew Lowe
 
Traits composition
Traits compositionTraits composition
Traits composition
Marielle Lange
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Sujit Majety
 
Graph Databases in the Microsoft Ecosystem
Graph Databases in the Microsoft EcosystemGraph Databases in the Microsoft Ecosystem
Graph Databases in the Microsoft Ecosystem
Marco Parenzan
 

Similar to Traits: A New Language Feature for PHP? (20)

Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
F# 101
F# 101F# 101
F# 101
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
F# for functional enthusiasts
F# for functional enthusiastsF# for functional enthusiasts
F# for functional enthusiasts
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Sparklis exploration et interrogation de points d'accès sparql par interactio...
Sparklis exploration et interrogation de points d'accès sparql par interactio...Sparklis exploration et interrogation de points d'accès sparql par interactio...
Sparklis exploration et interrogation de points d'accès sparql par interactio...
 
Stay fresh
Stay freshStay fresh
Stay fresh
 
The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
 
Xbase implementing specific domain language for java
Xbase  implementing specific domain language for javaXbase  implementing specific domain language for java
Xbase implementing specific domain language for java
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible research
 
Traits composition
Traits compositionTraits composition
Traits composition
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Graph Databases in the Microsoft Ecosystem
Graph Databases in the Microsoft EcosystemGraph Databases in the Microsoft Ecosystem
Graph Databases in the Microsoft Ecosystem
 

More from Stefan Marr

Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Stefan Marr
 
Seminar on Parallel and Concurrent Programming
Seminar on Parallel and Concurrent ProgrammingSeminar on Parallel and Concurrent Programming
Seminar on Parallel and Concurrent Programming
Stefan Marr
 
Optimizing Communicating Event-Loop Languages with Truffle
Optimizing Communicating Event-Loop Languages with TruffleOptimizing Communicating Event-Loop Languages with Truffle
Optimizing Communicating Event-Loop Languages with Truffle
Stefan Marr
 
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
Stefan Marr
 
Why Is Concurrent Programming Hard? And What Can We Do about It?
Why Is Concurrent Programming Hard? And What Can We Do about It?Why Is Concurrent Programming Hard? And What Can We Do about It?
Why Is Concurrent Programming Hard? And What Can We Do about It?
Stefan Marr
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Stefan Marr
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
Stefan Marr
 
Cloud PARTE: Elastic Complex Event Processing based on Mobile Actors
Cloud PARTE: Elastic Complex Event Processing based on Mobile ActorsCloud PARTE: Elastic Complex Event Processing based on Mobile Actors
Cloud PARTE: Elastic Complex Event Processing based on Mobile Actors
Stefan Marr
 
Supporting Concurrency Abstractions in High-level Language Virtual Machines
Supporting Concurrency Abstractions in High-level Language Virtual MachinesSupporting Concurrency Abstractions in High-level Language Virtual Machines
Supporting Concurrency Abstractions in High-level Language Virtual Machines
Stefan Marr
 
Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...
Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...
Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...
Stefan Marr
 
Sly and the RoarVM: Parallel Programming with Smalltalk
Sly and the RoarVM: Parallel Programming with SmalltalkSly and the RoarVM: Parallel Programming with Smalltalk
Sly and the RoarVM: Parallel Programming with Smalltalk
Stefan Marr
 
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
Stefan Marr
 
Sly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of ProgrammingSly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of Programming
Stefan Marr
 
PHP.next: Traits
PHP.next: TraitsPHP.next: Traits
PHP.next: Traits
Stefan Marr
 
The Price of the Free Lunch: Programming in the Multicore Era
The Price of the Free Lunch: Programming in the Multicore EraThe Price of the Free Lunch: Programming in the Multicore Era
The Price of the Free Lunch: Programming in the Multicore Era
Stefan Marr
 
Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...
Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...
Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...
Stefan Marr
 
Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...
Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...
Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...
Stefan Marr
 
Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...
Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...
Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...
Stefan Marr
 
Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...
Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...
Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...
Stefan Marr
 
Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...
Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...
Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...
Stefan Marr
 

More from Stefan Marr (20)

Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
 
Seminar on Parallel and Concurrent Programming
Seminar on Parallel and Concurrent ProgrammingSeminar on Parallel and Concurrent Programming
Seminar on Parallel and Concurrent Programming
 
Optimizing Communicating Event-Loop Languages with Truffle
Optimizing Communicating Event-Loop Languages with TruffleOptimizing Communicating Event-Loop Languages with Truffle
Optimizing Communicating Event-Loop Languages with Truffle
 
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
Tracing versus Partial Evaluation: Which Meta-Compilation Approach is Better ...
 
Why Is Concurrent Programming Hard? And What Can We Do about It?
Why Is Concurrent Programming Hard? And What Can We Do about It?Why Is Concurrent Programming Hard? And What Can We Do about It?
Why Is Concurrent Programming Hard? And What Can We Do about It?
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
 
Cloud PARTE: Elastic Complex Event Processing based on Mobile Actors
Cloud PARTE: Elastic Complex Event Processing based on Mobile ActorsCloud PARTE: Elastic Complex Event Processing based on Mobile Actors
Cloud PARTE: Elastic Complex Event Processing based on Mobile Actors
 
Supporting Concurrency Abstractions in High-level Language Virtual Machines
Supporting Concurrency Abstractions in High-level Language Virtual MachinesSupporting Concurrency Abstractions in High-level Language Virtual Machines
Supporting Concurrency Abstractions in High-level Language Virtual Machines
 
Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...
Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...
Identifying A Unifying Mechanism for the Implementation of Concurrency Abstra...
 
Sly and the RoarVM: Parallel Programming with Smalltalk
Sly and the RoarVM: Parallel Programming with SmalltalkSly and the RoarVM: Parallel Programming with Smalltalk
Sly and the RoarVM: Parallel Programming with Smalltalk
 
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
Which Problems Does a Multi-Language Virtual Machine Need to Solve in the Mul...
 
Sly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of ProgrammingSly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of Programming
 
PHP.next: Traits
PHP.next: TraitsPHP.next: Traits
PHP.next: Traits
 
The Price of the Free Lunch: Programming in the Multicore Era
The Price of the Free Lunch: Programming in the Multicore EraThe Price of the Free Lunch: Programming in the Multicore Era
The Price of the Free Lunch: Programming in the Multicore Era
 
Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...
Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...
Locality and Encapsulation: A Foundation for Concurrency Support in Multi-Lan...
 
Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...
Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...
Insertion Tree Phasers: Efficient and Scalable Barrier Synchronization for Fi...
 
Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...
Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...
Encapsulation and Locality: A Foundation for Concurrency Support in Multi-Lan...
 
Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...
Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...
Intermediate Language Design of High-level Language VMs: Towards Comprehensiv...
 
Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...
Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...
Virtual Machine Support for Many-Core Architectures: Decoupling Abstract from...
 

Recently uploaded

Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
BrainSell Technologies
 
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes..."Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
Anant Gupta
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
aslasdfmkhan4750
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
SynapseIndia
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
bhumivarma35300
 
Types of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technologyTypes of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technology
ldtexsolbl
 
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptxIntroduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
313mohammedarshad
 
Uncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in LibrariesUncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in Libraries
Brian Pichman
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
Tatiana Al-Chueyr
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
Zilliz
 
Figma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdfFigma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdf
Management Institute of Skills Development
 
Data Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining DataData Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining Data
Safe Software
 
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
shanihomely
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
maigasapphire
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
ssuser1915fe1
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
alexjohnson7307
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
July Patch Tuesday
July Patch TuesdayJuly Patch Tuesday
July Patch Tuesday
Ivanti
 
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSECHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
kumarjarun2010
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
aakash malhotra
 

Recently uploaded (20)

Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
 
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes..."Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
"Mastering Graphic Design: Essential Tips and Tricks for Beginners and Profes...
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
 
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
 
Types of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technologyTypes of Weaving loom machine & it's technology
Types of Weaving loom machine & it's technology
 
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptxIntroduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
 
Uncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in LibrariesUncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in Libraries
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
 
Figma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdfFigma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdf
 
Data Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining DataData Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining Data
 
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
July Patch Tuesday
July Patch TuesdayJuly Patch Tuesday
July Patch Tuesday
 
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSECHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
 

Traits: A New Language Feature for PHP?

  • 1. Please, feel free to interrupt me at any time.
  • 2. Do you use: Multiple Inheritance? Mixins?
  • 3. Traits A Language Feature for PHP? Stefan Marr PHP Unconference Hamburg 26-27 April 2008
  • 4. Agenda Introduction to Traits Traits Applied Traits for PHP: Trait versus Graft Roundup and Conclusion
  • 5. Which problem is to be solved? Single inheritance Simple but not expressive enough Leads to Code duplication Inappropriate hierarchies
  • 6. Traits Set of methods Possibly composed of other Traits Composition is unordered Composition operations Sum Exclusion Aliasing Can be flattened away
  • 8. TRAITS APPLIED Case Studies Illustrating Benefits of Traits
  • 9. Use Case for Traits in a PHP Library ezcReflection enhances PHP Reflection API Adds XDoclet like annotations for PHP Enhances type hinting using PHPDoc type annotations Illustrates solution for code duplication problems
  • 10. Refactoring ezcReflection with Traits original with Traits green parts are extracted to the Traits on the right-hand side, and will be removed from the classes
  • 11. Case Study: java.io [6] Mature code base, in wide use java.io Library from Java 1.4.2 79 classes, 25000 lines of code Results 12 classes changed 30 duplicated methods removed 14 Traits introduces
  • 13. Case Study: Smalltalk Collection Classes [10] Problem: code reuse vs. conceptual categorization Unnecessary inheritance Code duplication Methods to high in hierarchy Conceptual shortcomings Results for core collection classes 23 classes changed, 12% less code, 19.4% less methods
  • 14. Case Study: Smalltalk Collection Classes [10] Lessons Learned Traits simplify refactoring Very fine-grained traits Tools are important Traits enable to defer design of class hierarchy Improvements Uniformity, understandability, reuse
  • 15. Check for Limitations Code duplication Inappropriate hierarchies Diamond problem Fragile hierarchies Lack of composition control     
  • 16. TRAITS FOR PHP Trait versus Graft
  • 17. What is a Graft? Stateful, non-breakable entity of reuse Derived from the Traits notion Proposed with RFC: Non Breakable Traits for PHP Why Graft? From The Grafter's Handbook by R.J. Garner
  • 18. A Comparison Traits Purpose, reuse of behavior Features Stateless Flattenable Explicit conflict resolution Highly composable Notion Language-base Copy and Paste Grafts Purpose, reuse of modules smaller then classes Features Stateful Hides complexity Conflict avoidiance Strong encapsulation Notion Delegation with self-impersonation
  • 19. Traits Syntax and Semantics trait A { public function small() { echo 'a' ; } public function big() { echo 'A' ; } abstract public function doBFoo(); public function doAFoo() { echo 'AFoo uses BFoo: ' ; $this ->doBFoo(); } } trait B { public function s mall() { echo 'b' ; } public function big() { echo 'B' ; } public function doBFoo() { echo 'B-FOO' ; } } class Talker { use A, B { B::small instead A::small, A::big instead B::big, B::big as talk } } $talker = new Talker(); $talker ->small(); // b $talker ->big(); // A $talker ->talk(); // B $talker ->doAFoo(); // AFoo uses // BFoo: B-FOO $talker ->doBFoo(); // B-FOO
  • 20. Grafts Syntax and Semantics graft Counter { private $cnt = 0 ; public function inc() { $this ->cnt++; } public function reset() { $this ->cnt = -1; $this ->inc(); } } graft DB { private $db; public function connect() { $this ->db = new FooDB( 'param' ); } public function reset() { $this ->db->flush(); $this ->db = null; } public function doFoo(){echo 'foo' ;} } class MyPage { include Counter { public incCnt() as inc(); public resetCnt() as reset(); } include DB { public connect(); public reset(); } public function inc() { /* next page */ } } $page = new MyPage(); $page ->connect(); $page ->incCnt(); //($Countercnt == 1) $page ->resetCnt(); // $Countercnt = 0; $page ->inc(); // goto next page $page ->doFoo(); // FATAL ERROR
  • 21. My Mental Image Traits Grafts
  • 22. ROUNDUP AND CONCLUSION Trait Support, Discussion, Resume
  • 23. Environments Supporting Traits Squeak: In standard distribution since 3.9 [11] Trait named: #TDrawing uses: {} draw ˆself drawOn: World canvas in: bounds bounds self requirement Object subclass: #Circle instanceVariableNames: ’’ traits: { TDrawing } ...
  • 24. Environments Supporting Traits Scala: static-typed language running on JVM [7] trait TDrawing { def draw() : Any = drawOn(World.canvas(), bounds) def bounds() : Any } class Circle extends TDrawing { ... }
  • 25. Environments Supporting Traits Perl6: Flavor of Traits with states called Roles [12] role TDrawing { method draw() { return drawOn(World.canvas(), bounds); } } class Circle does TDrawing { ... }
  • 26. Environments Supporting Traits Approaches for plain Java Using AspectJ [2] Utilizing an Eclipse Plugin [8]
  • 27. Environments Supporting Traits Approaches for plain Java Using AspectJ [2] Utilizing an Eclipse Plugin [8]
  • 28. Environments Supporting Traits C#: Prototype Implementation for Rotor [9] trait TDrawing { public Object draw() { return drawOn(World.canvas(), this .bounds); } requires { public Object bounds(); } } class Circle { uses { TDrawing } ... }
  • 29. Resume Traits are a appropriate language construct to: Achive conceptual consistent class hierarchies Avoid code duplication Enhance class compositon capabilites Available for different languages Two different flavors proposed for PHP
  • 30. Request for Comments Traits for PHP Version: 1.5 Date: 2008-03-06 Author: Stefan Marr Wiki: http://wiki.php.net/rfc/traits reST: http://www.stefan-marr.de/rfc-traits-for-php.txt HTML: http://www.stefan-marr.de/artikel/rfc-traits-for-php.html Non Breakable Traits for PHP Version: 1.0 Date: 2008-02-29 Author: Joshua Thompson Wiki: http://wiki.php.net/rfc/nonbreakabletraits
  • 31. Basic Literature Main Article about Traits [3] S. DUCASSE, O. NIERSTRASZ, N. SCHÄRLI, R. WUYTS, AND A. P. BLACK, Traits: A Mechanism for Fine-Grained Reuse , ACM Trans. Program. Lang. Syst., 28 (2006), pp. 331–388. Traits Extensions [1] A. BERGEL, S. DUCASSE, O. NIERSTRASZ, AND R. WUYTS, Stateful Traits and their Formalization , Journal of Computer Languages, Systems and Structures, 34 (2007), pp. 83–108. [4] S. DUCASSE, R. WUYTS, A. BERGEL, AND O. NIERSTRASZ, User-Changeable Visibility: Resolving Unanticipated Name Clashes in Traits , SIGPLAN Not., 42 (2007), pp. 171–190.
  • 32. Literature [1] A. BERGEL, S. DUCASSE, O. NIERSTRASZ, AND R. WUYTS, Stateful Traits and their Formalization , Journal of Computer Languages, Systems and Structures, 34 (2007), pp. 83–108. [2] S. DENIER, Traits Programming with AspectJ , RSTI - L'objet, 11 (2005), pp. 69–86. [3] S. DUCASSE, O. NIERSTRASZ, N. SCHÄRLI, R. WUYTS, AND A. P. BLACK, Traits: A Mechanism for Fine-Grained Reuse , ACM Trans. Program. Lang. Syst., 28 (2006), pp. 331–388. [4] S. DUCASSE, R. WUYTS, A. BERGEL, AND O. NIERSTRASZ, User-Changeable Visibility: Resolving Unanticipated Name Clashes in Traits , SIGPLAN Not., 42 (2007), pp. 171–190. [5] S. MARR AND F. MENGE, ezcReflection , SVN Repository, eZ Components, January 2008. http://svn.ez.no/svn/ezcomponents/experimental/Reflection. [6] E. R. MURPHY-HILL, P. J. QUITSLUND, AND A. P. BLACK, Removing Duplication from java.io: a Case Study using Traits , in OOPSLA '05: Companion to the 20th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, New York, NY, USA, 2005, ACM, pp. 282–291.
  • 33. Literature [7] PROGRAMMING METHODS LABORATORY, Traits for Scala , Programming Language, Ecole Polytechnique Fédérale de Lausanne, 2006. http://www.scala-lang.org/intro/traits.html. [8] P. J. QUITSLUND, E. R. MURPHY-HILL, AND A. P. BLACK, Supporting Java traits in Eclipse , in eclipse '04: Proceedings of the 2004 OOPSLA workshop on eclipse technology eXchange, New York, NY, USA, 2004, ACM, pp. 37–41. [9] S. REICHHART, Traits in C# . Video of Talk at Microsoft Research, September 2005. [10] N. SCHÄRLI, Traits — Composing Classes from Behavioral Building Blocks , PhD thesis, University of Berne, Feb. 2005. [11] SOFTWARE COMPOSITION GROUP, Traits for Squeak , Smalltalk VM, University of Berne, December 2006. http://www.iam.unibe.ch/ scg/Research/Traits/index.html. [12] L. WALL, Apocalypse 12: Class Composition with Roles , tech. report, The Perl Foundation, 2004. http://www.perl.com/pub/a/2004/04/16/a12.html?page=11.
  • 34. Any questions? Discussion What du you think? Traits vs. Grafts
  • 35. TRAITS ENHANCED User-Changeable Visibility and Stateful Traits
  • 36. User-Changeable Visibility Add flexibility to conflict handling Introduces “Trait private” methods Methods visibility changeable on composition
  • 37. Stateless Traits Problem: stateless Traits are incomplete, not self-contained units of reuse Required state accessors bloat the interfaces Encapsulation is violated by public accessors Reuse, composition is hampered State access introduces fragility
  • 39. Stateful Traits Solution requirements: Preserver faltening property Minimal and general approach Language independed Solution State is private to the Traits scope Client can request access under new private name Client can merge state