develooper Front page | perl.perl6.language | Postings from January 2004

Re: A modest question

Thread Previous | Thread Next
From:
Piers Cawley
Date:
January 7, 2004 00:28
Subject:
Re: A modest question
Message ID:
m21xqc6u3n.fsf@obelisk.bofh.org.uk
chromatic <chromatic@wgz.org> 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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About