A New Trait Implementation

Research Team:
RMod
Team leader (HDR):
Stéphane Ducasse
Project leader and contact:
S.Ducasse

Project Context

Inheritance is well-known and accepted as a mechanism for reuse in object-oriented languages. Unfortunately, due to the coarse granularity of inheritance, it may be difficult to decompose an application into an optimal class hierarchy that maximizes software reuse. Existing schemes based on single inheritance (e.g., in Java), multiple inheritance (e.g., in C++), or mixin (e.g., in Ruby), all pose numerous problems for reuse.

To overcome these problems, we designed a new composition mechanism called Traits [1], now included in programming languages such as PHP, Perl and Pharo/Smalltalk. Traits are pure units of behavior that can be composed to form classes or other traits. The trait composition mechanism is an alternative to multiple or mixin inheritance in which the composer has full control over the trait composition. The result enables more reuse than single inheritance without introducing the drawbacks of multiple or mixin inheritance.

Problem

Pharo is a new open-source Smalltalk-inspired programming language and environment [2]. It provides a platform for innovative development both in industry and research. Traits are integrated in Pharo but barely used due to a lack of support in the development environment. The current implementation of traits in Pharo merges the trait methods into the classes that use the trait. This merging of external methods into classes makes the implementation of the development tools harder.

Work plan

To solve this problem, the student will have to:

  • evaluate alternative implementations of traits that do not merge methods into classes;
  • implement the best alternative in Pharo;
  • review possible ways to browse, visualise and implement source code with traits;
  • adapt the Pharo development tools so that they become trait aware (e.g., code browser, refactoring tools, and versioning tools).

Benefits for the Pharo community

  • Simplify writing new code with traits and help understand trait-based existing code;
  • Enable rewriting of non trait-based code with traits to improve its design and reuse;
  • Provide a basis to continue research around traits with a better implementation.

Benefits for the student

  • Integration into a prolific research group, fond of software development and programming languages;
  • Understanding of how programming languages and IDEs are implemented;
  • Potential integration as a master and/or PhD student either within the group or within one of its numerous partners around the world (Switzerland, Chile, Belgium, Argentina, Italy).

Requirements

  • Having a good understanding of object-oriented programming;
  • Being eager to learn a new programming language and environment.

Bibliography

[1] S. Ducasse, O. Nierstrasz, N. Schärli, R. Wuyts, and A. P. Black. Traits: A Mechanism for fine-grained Reuse. In TOPLAS: ACM Transactions on Programming Languages and Systems 28(2) p. 331—388, March 2006. http://scg.unibe.ch/archive/papers/Duca06bTOPLASTraits.pdf

[2] A. Black, S. Ducasse, O. Nierstrasz, D. Pollet, D. Cassou, and M. Denker. Pharo by Example, Square Bracket Associates, 2009. http://pharobyexample.org/

[3] D. Cassou, S. Ducasse, and R. Wuyts. Traits at Work: the design of a new trait-based stream library. In Journal of Computer Languages, Systems and Structures 35(1) p. 2—20, 2009. http://scg.unibe.ch/archive/papers/Cass08a-NileNewKernel-ComputerLanguages.pdf

[4] T. Van Cutsem and M.S. Miller. Traits.js: Robust object composition and high-integrity objects for ECMAScript 5. In PLASTIC'11: international workshop on Programming Language And Systems Technologies for Internet Clients, 2011. http://es-lab.googlecode.com/files/traitsJS_PLASTIC2011_final.pdf