in reply to Informal Poll: why aren't you using traits?

I work with simple enough class hierarchies that traits would not be worthwhile.

That said, if you want to get others to use them, it would probably be most useful to clarify what kinds of problems traits are meant to solve, and how you can discover where they make sense in your code.

  • Comment on Re: Informal Poll: why aren't you using traits?

Replies are listed 'Best First'.
Re^2: Informal Poll: why aren't you using traits?
by Ovid (Cardinal) on Nov 20, 2005 at 20:48 UTC

    Problems they solve/when to use them:

    • Whenever you've duplicated behavior across unrelated classes.
    • Any time you might think about MI and it's only for code reuse (in other words, the subclass is not a more specific type of a super class)
    • Any time you might want a Java-style interface but you also want an implementation to go with that.
    • Any time you might want to use mixins (have you ever considered exporting methods?)

    Cheers,
    Ovid

    New address of my CGI Course.

      As I said, I don't need them. But you may want to look at Class::Trait's documentation with an eye to making those points early. In particular I think that it is more important to be fast to explain what traits can do for you than to say what they are.