"Brent Dax" <[EMAIL PROTECTED]> writes:
> # From: Uri Guttman [mailto:[EMAIL PROTECTED]]
> # BD> equivalent) in method lookups? In other words, if
> # $spot is declared to
> # BD> hold a Dog, can we assume that it does, thus skipping
> # the check with
> # BD> 'ref' normally used for method dispatch? Would this even buy us
> # BD> anything? Why am I asking myself these questions? Why are the
> # BD> orderlies putting me in a white truck?
> #
> # no, that won't work. you can always bypass that at runtime in too many
> # ways. as damian stated, runtime checks for objects are always in
> # effect. if a method isn't found or handled by AUTOLOAD or something it
> # is fatal (unless caught, of course). the method itself will
> # always need
> # to check its arguments if it cares about whether a class or object is
> # the invocant (i like that word. thanx, damian!).
>
> I'm not sure if you understood what I meant there. I meant that, if we
> know $spot is supposed to have a Dog in it, can we avoid checking if it
> really does (at least some of the time) and maybe shuck some overhead by
> doing so? Perhaps we only check after each assignment to $spot, and
> when we check we set a flag saying that it's already been typechecked so
> we don't have to do it again. Whatever, methinks I may optimizing too
> early. We all know what Knuth says about that.
You missed out another checking possibility:
sub Foo::method { bless $_[1], 'Bar' }
my Dog $spot = Dog.new(type => 'Poodle');
Foo->method($spot);
Unless I've totally misunderstood the current proposals for what
happens with arguments passed in, it's still going to be possible to
rebless an argument, therefore $spot will need to be rechecked after
every method call to which it is passed as an argument.
--
Piers Cawley
www.iterative-software.com