chromatic <[EMAIL PROTECTED]> writes: > On Tue, 2004-01-06 at 22:26, Austin Hastings wrote: > >> So on the grand balance of utility, what are the metrics that traits are >> supposed to help improve? > > Two big ones: > > - naming collections of behavior that are too fine-grained to fit into > classes cleanly > - enabling finer-grained code reuse > > Consider a method that needs to print an object. You might require a > String: > > sub print_it ( String $thingie ) > { > print $thingie; > } > > Why does it have to be a String, though? What prevents it from working > with anything that can stringify, besides the overly restrictive > signature? What if you could say (the Perl 6 equivalent of): > > sub print_it ( does Stringify $thingie ) > { > print $thingie.stringify(); > } > > That's both more general and something more specific. By asking for > what you really want, you're not coding everyone else into a corner.
In this particular case I prefer the Smalltalk thing of requiring all objects to have a C<print_on($aStream)> method and not even requiring that C<$aStream> satisfy the Stream role. But that's probably a matter of taste. -- Beware the Perl 6 early morning joggers -- Allison Randal