Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In the Moose / Perl 6 world, we use roles for this. (I know the idea is borrowed from elsewhere, but I don't know where.) As a Perl 6 programmer, I have almost completely given up on traditional inheritance, because roles capture everything I want from inheritance with greater robustness.

To be fair to original article, this does mean I'm doing my best to avoid type hierarchies...



I know the idea is borrowed from elsewhere, but I don't know where.

It probably originated in Flavors, an object system for Lisp (see http://en.wikipedia.org/wiki/Flavors_%28computer_science%29)


It was a combination of dissatisfaction with multiple inheritance (see Perl 5, C++), interfaces (see Java), and mixins (see Perl 5, Ruby), as well as an acknowledgement that aspects (see Java) and multimethods (see Common Lisp) solve part of the problem well and part of the problem poorly.

Then Allison and I saw Dr. Black present the Smalltalk traits paper and she realized that their formalism was exactly what I'd been talking about informally, so we borrowed that instead.


How are roles different from mixins?

The only difference that I can think of is that mixins are declared at class declaration, is that what you mean?


Roles have specific composition rules which forbid name collisions; there's no last-in wins rule. Roles also provide type allomorphism which is much less ambiguous than duck typing.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: