Trans
10/15/2007 5:49:00 PM
This is an interesting discussion --what qualifies as "traits".
On Oct 15, 8:50 am, "Robert Dober" <robert.do...@gmail.com> wrote:
> Actually Traits allow both
> when you compose traits conflicts will be created
> when you use traits (that is when you inject the methods) they can
> perfectly be overridden.
>
> Example
> t1 = trait { def a; 42 end }
> t2 = trait { def a; 46 end }
> t3 = t1 + t2
> class A
> use t3
> end
> A.new.a --> Conflict
> but
> class A
> use t1 # or t3 for that matter ### flattening is going on here
> def a; 22 end
> end
> A.new.a --> 22
> according to Schaerli's paper you can even do
> t4 = trait { use t1; def a; 222 end }
> no conflicts here
Interesting. But why not have a default definition based on
combination order instead of raising a Conflict? One can always
override/redefine. But having a conflict forces one to redefine, which
seems more limiting to me. But maybe I missing something, I haven't
read the paper (link?).
> The flattening property of traits will however hide the trait from the
> inheritance chain, behavior is composed not inherited that is an
> important trait of traits - forgive the pun ;).
Is it an absolutely necessary trait, though? The theory defines
flattening b/c it is offering an alternate means of composition.
However, we have module chains at our disposal. Can we not take
advantage of them in our implementation and still be considered
"traits"? Might we not view Ruby's linearization of the inheritance
chain as an effective means of "flattening", whether it is or not in
the strictest sense? Or are there some other important reasons for
flattening (especially one that Ruby's module chains can't emulate)?
> > If someone come to the idea to allow modules to have merits from both
> > mixins and traits at once (without demerit), I'd love to hear.
>
> Hmm, I almost fail to see what merit modules have that traits do not have?
> That you can say isa? for an instance of a class that had a module mixed in?
> Maybe, no idea if this is worth it.
That's one reason. But more importantly, calling super, ie. method
inheritance. Does the formal design of traits have super?
T.