Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: AUTOLOAD does not scale

by adrianh (Chancellor)
on May 27, 2004 at 12:21 UTC ( [id://356872]=note: print w/replies, xml ) Need Help??


in reply to AUTOLOAD does not scale
in thread OO Inheritence

Two AUTOLOADs cannot coexist amicably in the same inheritance tree. Try it, one masks the other

While I am not a fan of AUTOLOAD it is perfectly possibly to have multiple AUTOLOADs coexisting amicably in the same inheritance tree. (using SUPER and NEXT).

Replies are listed 'Best First'.
Re: Re: AUTOLOAD does not scale
by dragonchild (Archbishop) on May 27, 2004 at 15:19 UTC
    --! Bad saint, no cookie.

    Yes, it's perfectly possible to have AUTOLOADs in the same inheritance tree. You can even have them dispatch to one another. And, this would be a very obfuscated version of spaghetti programming. (Yes, spaghetti that's further obfu'ed!)

    Think for a second about how you would go about maintaining that kind of programming. I know which one I'd prefer to maintain!

    (By maintain, I mean that there was a wizard who wrote the software, N normal humans who extended it, and now I am handed the mess.)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      NEXT or something like it will be built into Perl 6. People will start using it. And abusing it. And much obfu/spaghetti code will be written. But I'm still glad it's there in case I want it. (And I didn't know there was a NEXT for Perl 5, so thanks adrianh (for informing me of it)...and TheDamian (for writing it)!).

      And let me reiterate that the only reason I disagreed with rir in the first place was because of the complaint about having multiple AUTOLOAD's in the inheritance tree, yet the OP had only one AUTOLOAD, in the base class, and with no multiple inheritance as in rir's later example. I might say the same things about maintainability when you start using multiple inheritance, but I won't :-)

      --! Bad saint, no cookie.

      The statement that "Two AUTOLOADs cannot coexist amicably in the same inheritance tree" is factually incorrect and that's the only point that I am making.

      I rarely use AUTOLOAD since there is usually a better alternative. Yes it can be used badly to produce ghastly code. However, just like local, it can occasionally be very useful. It is perfectly possible to write very straightforward non-obfu code with AUTOLOAD.

      Talking about how to use AUTOLOAD well/badly is a good thing. Blanket statements that are factually incorrect are not (IMHO anyway. YMMV).

Re: Re: AUTOLOAD does not scale
by ihb (Deacon) on May 30, 2004 at 19:58 UTC

    it is perfectly possibly

    Remove "perfectly" from that sentence and I'll agree with you. From NEXT's documentation:

    Because it's a module, not an integral part of the interpreter, NEXT.pm has to guess where the surrounding call was found in the method look-up sequence. In the presence of diamond inheritance patterns it occasionally guesses wrong.

    It's also too slow (despite caching).

    I repeat what I've said earlier, that using AUTOLOAD may very well cause you a bigger problem than the one you tried to solve. (Re: is autoload bad style?)

    ihb

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://356872]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-03-28 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found