Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Would what MTOS is calling taggable, scorable qualify as a role or trait? I'm thinking yes, but the examples I've seen don't quite fall inline.

This "-able" thing is more aligned to how people use Java interfaces, which is only one way in which Roles/Traits can be used. Most of the time my Roles are named "HasDBICSchema" or something similar and simply provide, in this case, a DBIx::Class (commonly shortened to DBIC) Schema object. The reality is that Roles/Traits are still new, the smalltalk folks who invented traits are not seeing a lot of trait usage in the community (from my limited knowledge, so dont take that as 100% fact). The most usage is currently with Roles in the Moose community.

Roles seem to be a more simple and basic implementation of the traits idea.

Actually, its the opposite, roles can provide class attributes/slots which complicates them much more than traits which only allow methods. The deeper discussion of why this is so, is way out of the scope of this post, suffice to say that when I wrote Moose::Role I had a discussion with the original authors of the traits paper (whom I had already known from back when I had written Class::Trait), and when I asked them if they had figured out how to do slots in traits they said "No, but let us know if you figure it out". They have since written their own smalltalk version with attributes/slots and ended up having to add public/protected/private to Smalltalk and I got the impression they were generally unhappy with the result.

Traits includes more advanced features like overloaded operators, required method labels, conflict resolution, aliases and summation.

Actually, Moose::Role supports required methods, conflict resolution and aliasing. Summation and conflict detection are just how roles work, so I dont consider it a feature. Only Class::Trait supports overloaded operators, and the pain of having to write that is exactly why Moose::Role does not support overloaded operators.

Roles will be built-in to Perl 6. Traits will not.

Traits can really be viewed as a subset of Roles. Perl 6 doesnt support explicit method requirement, but simply doing method foo { ... } using the yadda-yadda-yadda operator will give you pretty much the same thing. As for conflict resolution, you can do that in a more manual way in Perl 6 then you can in Class::Trait or Moose::Role, but it is still generally possible.

If I wanted to implement roles in MT which CPAN module should I use? Class::Role, Class::Roles, Perl6::Roles? I'd assume the latter given the dates, docs and Perl6 namespace. If Perl6::Roles is the answer to the above, how up to date is it in terms of the current Perl6 implementation?

None of the above, all those modules should be considered toy implementations and are all woefully incomplete. The only complete and thoroughly tested Role implementation on the CPAN is Moose::Role.


In reply to Re: Sanity Check: Roles vs. Traits by stvn
in thread Sanity Check: Roles vs. Traits by tima

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2023-12-04 23:16 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (25 votes). Check out past polls.