Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I find your terminology a bit confusing. There are Perl 6 "traits", then there are Perl 6 "Roles", which are somewhat based on the ideas in the Traits papers.

I don't really see Perl 6 traits as being all that much like Mix-ins though. Personally, I am not so sure what Perl 6 traits will be most useful for. The Apocolypse says:

A class declaration may apply various traits to the class. (A trait is a property applied at compile time.) When you apply a trait, you're accepting whatever it is that that trait does to your class, which could be pretty much anything. Traits do things to classes. Do not confuse traits with roles, which are sworn to play a subservient role to the class. Traits can do whatever they jolly well please to your class's metadata.
It sounds to me like a place where only the genius or the insane will venture (at least regularly). Either way, I am still not 100% sure what good they will provide other then to implement "deep-level" things like AOP, or to replace the "symbol-table-hacking" stuff. But I am not even sure about that, of course if anyone cares to enlighten me, it would be much appreciated.

As for Perl 6 Roles, these I feel are more akin to Mix-ins, although not quite really. From my (limited) understanding, Perl 6 Roles will really be a fancy way to set up a delegation-type relationship between classes and Roles (which I see as being partial or deffered classes). This is very different from the Traits idea it was originally based upon (which in some ways are very much like Mix-ins, just with a clear set of rules and a means to enforce them).

Confusion over terminology aside, I would like to comment on some of what you list as problems for "mixins, traits, etc":

be universally usable
I don't believe this to be true, and IMO one of the reasons why things like this get a bad wrap. Any experienced OO programmer knows that you have to know when to say when, or you end up with the God-Object-Uber-Base-Class-From-Hell. It is highly unlikely that you can create mix-ins or traits that can be all things to all classes. At some point you need to weigh the benefits of code-reuse vs. code-complexity. When it really comes down to it, polymorphism a more powerful means of code-reuse anyway.

I would recommend reading this Traits paper to see how they refactored the Smalltalk Collection hierarchy with Traits. It shows that building Traits, should not be treated as just building small, incomplete classes to be squished together at a later time, but instead a rethinking of how classes are/can be composed. Its very informative, and likely relevant to how one might use Perl 6 traits/Roles as well.

Keep in mind, that there is nothing in the Traits rulebook that says you cannot implement a Trait with no methods and only requirements (which amounts to the equivalent of a Java interface). And I would expect that Perl 6 Roles and traits works that way too.

avoid namespace clashes
Well, I imagine Perl 6 traits, being compile-time beasts, will not even allow this. Perl 6 Roles have means of working around this by fully qualifying the name. And Traits are much like Perl 6 traits in this, in that there are rules to govern namespace conflicts and they will all either be resolved at compile time, or just not compile.
Comparability and equality
~snip~
There is such an instance that is identical except for the difference in their traits.
Is it the same?
I would argue that they are clearly not the same instance, but that it not to say that they are not equal to one another. Maybe I am misunderstanding you, but I see determining comparability and equality as not really having to do with the concept of "mixins and traits" and more having to do with the requirements of your specific application. For some classes equality may be their UUID, for others, it is equivilant internal data, its really all about what you want to do with it. Again, maybe I am misunderstanding you here, please correct me if I am.

In the end, all these things (Perl 6 traits, Perl 6 Roles, Traits (ala the papers)) are still toys. And much as dragonchild points out, they will be feared initially, and if they prove useful, will eventually become accepted parts of how we all code OO. Even after having written Class::Trait, I have yet to find a real good use for it, other than something to play around with. And I am waiting on either Class::Roles or Class::Role to see how Perl 6 Roles might be useful, and I suppose I will need to wait for Perl 6 itself to see how Perl 6 traits might play out.

-stvn

In reply to Re: Open to debate on mixins and traits. by stvn
in thread Open to debate on mixins and traits. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (11)
    As of 2014-08-29 00:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (275 votes), past polls