What is the difference between a Squeak/Pharo Trait and a Newspeak Mixin?

Viewed 2252

So Squeak/Pharo support Traits and Newspeak has Mixins. What is the difference? Traits have no instVars but Mixins have?

3 Answers

Traits are composed using a composition rule. Conflicts have to be resolved manually, it cannot happen that a trait accidentally overrides another method with the same name.

Mixins are composed by order and thus have fragility problems similar to multiple inheritance.

In Newspeak all classes are mixins. Here are some snippets from Gilad Bracha's answer to a similar question in Newspeak discussion forum:

Mixins are not a feature of Newspeak per se. That is, we did not design the language saying, ok, now we'll add mixins. Mixins fall out automatically from class nesting and message based semantics. That is, if you have virtual classes, you have mixins unless you actually ban them. ...

Traits attempt to address perceived problem of mixins.

  1. There is very little real experience indicating that these perceived problems are real.
  2. Traits are restricted to be stateless. This simplifies matters, but does not handle all cases of interest. In fact, there are now research papers attempting to add state to traits.

Traits are entirely subsumed by a more general model, which I devised many years ago in my PhD thesis (available off my web site, if you really want to dig deep). ... I would like to examine how we might incorporate these combinators into Newspeak. ...

Related