I think you missed stephen's point.

zigster's argument against using AUTOLOAD was that (by his understanding) it tied the methods to the object's implementation and that exposed internal information that you shouldn't expose.

There are two major things wrong with that argument.

My response was that if you choose to tie the autogenerated methods to the implementation, when you change the implementation it is not hard to add normal methods that maintain the old interface even though the implementation changed.

stephen's response is that zigster's assumption that you had to tie the interface to the implementation was wrong. And he replied with actual code showing how to autogenerate methods based on a data structure that can be used to control the interface independently from the internal data structure.

So yes, stephen is munging accessor methods and mutators with AUTOLOAD. However he has done it in a way where changes to the structure of the object do not show up in the interface.

As an incidental note, I have used AUTOLOAD for a variety of things, but I have not yet used AUTOLOAD as a way to produce accessor methods and mutators for end-user objects. However I have used it as a replacement for auto-generated SWIG tie implementations (IOW for objects that Perl is using) with lazily implemented run-time accessors. It worked well. I got both loading and runtime to be substantially faster than the original. Maintainability was the same.

Based on that I have to say that I find AUTOLOAD to be no more or less maintainable than any other way of auto-generating code. If you think about trying to write self-modifying assembly you would think that auto-generated code is the worst idea in the world. However then you go out and use a compiler that does what? Oh right, it autogenerates code to run later!

AUTOLOAD should have a huge sign on it saying, "use with extreme caution", but it doesn't need one saying, "you should never use this".

That said I use it in only a tiny fraction of my code. But that fraction tends to be key code which a lot of other code builds off of...


In reply to Re (tilly) 4: Re: Perl and Objects, how do you resolve the two? by tilly
in thread Perl and Objects, how do you resolve the two? by frankus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.