in reply to Traits as Method Exporters
(I think you mean Roles, not Traits -- in Perl 6 terms, there's a big difference.)
You're right in that viewing a role as a gussied up export works, but it works in the same way that you can write OO code in C. Sure, you have to maintain your list of methods appropriately and pass around the invocant manually, but you can get some of the benefit with a bit of clever work.
What you're missing is that the roles that apply to a class actually affect the type system. That is, you can write a method which expects an argument that does the Stringify role -- because you're going to print it. The callers of that method don't have to coerce their arguments into new, temporary String objects because you didn't require that that argument be a string, just that it does something sensible when you treat it as a string.
Of course, you do get the benefits of code-reuse without having to maintain a fragile and usually precarious class hierarchy with the plain-Exporter approach.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Roles as Method Exporters
by simonm (Vicar) on Apr 11, 2004 at 05:03 UTC |