I'd like to make a quiet protest on behalf of all the programmers who come into a project 4 years into it and who have to deal with the abysmal dreck that is AUTOLOAD. I have never once, and I mean never, have come across an AUTOLOAD whose existence was justified. Ever. Most of the time, it's an attempt to circumvent proper encapsulation and is a perfect example of false Laziness. Something like:
sub AUTOLOAD { my ($self, $method_name) = @_; $self->{$method_name} = $_[0] @_; return $self->{$method_name}; }
Why is this bad? Oh, let me count the ways!
  1. No checking, either compile or runtime, for typos.
  2. You can create members on the fly.
  3. $self->FooBar and $self->foobar are different.
  4. There is a much cleaner WTDI, using a base class that will receive a list of attributes to use and auto-generate your getters/setters/mutators for you. This option even has the benefit of being self-documenting and provides runtime checking for typos.
Would someone please give me a place, in production code, where AUTOLOAD shines over proper decomposition?

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

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Re: goto and AUTOLOADed methods by dragonchild
in thread goto and AUTOLOADed methods by fergal

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.