in reply to Re: Re: oop - obvious AUTOLOAD question
in thread oop - obvious AUTOLOAD question

it seems a bad time to imply that an arcane construct is faster than a normal call.

I don't think anyone attempted to imply anything about the efficiency of using goto. As you almost pointed out, if you are using AUTOLOAD in the first place, efficiency probably isn't your primary consideration. The real point to it is correctness. Using goto hides the fact that the code is AUTOLOAD'd. The AUTOLOAD'd code can then do things like call caller() without worrying or wondering whether it was called directly.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Re: Re: oop - obvious AUTOLOAD question
by rir (Vicar) on Sep 26, 2002 at 11:48 UTC
    I think fglock's shortcut ... stack frame comment seems difficult to read
    any other way. If I'm missing something here please let me know because I
    think you're way off-base.

    I find your other point difficult to swallow. It sounds like conventional
    wisdom but is not.

    Correctness, is good. But hiding where a routine was called from is not correct.

    Why lie about a code trace?!

    Correct would be to do a two-step dance: have your routine
    use caller and have AUTOLOAD use it too.

      It may be just "cargo cult".

      perlsub says "most" routines would do it, but you don't "have" to.

      from perlsub:

      Most AUTOLOAD routines will load in a definition for the subroutine in question using eval, and then execute that subroutine using a special form of ``goto'' that erases the stack frame of the AUTOLOAD routine without a trace.

      note: I did think it was a performance issue - it is not.

      Correctness, is good. But hiding where a routine was called from is not correct.

      It may be, for certain values of "correct" :-)

      If I autoload methods that log (as an example of use of) caller() information, I would not like seeing in my logs:

      My::Lazy::method called from My::Lazy::AUTOLOAD [... later ...] My::Lazy::method called from Some::Other::method [... and ...] My::Lazy::method called from Yet::Another::method

      While correct, in a sense of the word, the information given in the first of these lines is not useful. And I don't want to make AUTOLOAD smart enough to know what to do with caller information in every case. That would defeat the purpose of AUTOLOAD. And so, I use goto instead.

      With goto, I get the caller information I would get if I were not using AUTOLOAD.

      If your correctness criterion is that the sub should behave as if it was already in existence, and not autoloaded, then goto provides that correctness.

      The Sidhekin
      print "Just another Perl ${\(trickster and hacker)},"

        Your argument seems weak because AUTOLOAD will be smart
        enough to make the routine, but too stupid to know whether
        to use caller itself.

        If this is debugging info there is no reason to avoid logging
        the AUTOLOAD call also. If it is not debugging info, I
        don't see a reason to expose implementation details to
        users.

        I agree with The Sidhekin that correctness is an amorphous thing.