Recently I presented a Perl 6 overview talk at a Java conference. The audience was mostly mute, which is unfortunate as I wanted to hear some feedback or at least some groans of pain, but there was one Lisp programmer in the front row that asked some interesting questions.
One was "Perl 6 support interfaces?" meaning Java style interfaces. Figuring that we now have proper subroutine prototypes and assuming forward declarations stayed in the language, sure we'd effectively have interfaces. Thinking on it afterwards, there's a bit more to it that that. If I was to declare an abstract class using "interfaces" in Perl 6, I'd figure it would look something like this: class Toilet; method flush_capacity ($liters); method plunge (); method flush (); method fill ($liters); method water_height (); method seat_up (); method seat_down (); and then all you have to do is subclass and implement those methods. In order for this to really be interfaces, there would have to be a few more things. - Overriding methods would have to have the same signature as the parent. If not, a warning or error would be issued. class Crapper isa Toilet; # Ok. Variable name different, signature the same. method flush_capacity ($litres) { ... } # Ok, but illustrates that signatures will have to have types # to really be useful. method fill ($gallons) { ... } # Not ok. Wrong signature. method plunge ($plunger) { ... } # Ok? The old signature will still work, we've just added # an extra, optional argument. [1] method water_height (;$metric_or_imperial) { ... } - Methods left unimplemented should issue a warning or error at compile-time. Anything left for autoloading should probably be declared as such. class Loo isa Toilet; method water_height () is autoloaded; Here's some open problems: Would this be the default behavior for overridden methods, or will the parent class/methods have to be declared "is interface" for the signatures to be enforced on subclasses? Will interfaces be ignorable? What if a subclass adds extra, optional arguments to a method, is that ok? What about the return type? If you're doing strict OO it would be nice to specify the signature of the return value as well, which will get interesting to be able to describe totally the various ways in which a method can return in different contexts. [1] I don't know what Perl 6 signatures will use for optional arguments, so I'll just use the Perl 5 style. -- Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/ Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One Do you have a map? Because I keep getting lost in your armpits.