in reply to Re^6: Modules for autogenerating accessor/mutator methods
in thread Modules for autogenerating accessor/mutator methods

Off the top of my head, delegation.
  • Comment on Re^7: Modules for autogenerating accessor/mutator methods

Replies are listed 'Best First'.
Re^8: Modules for autogenerating accessor/mutator methods
by tlm (Prior) on Jun 05, 2005 at 02:32 UTC

    That's an instructive example. I now see tilly's point much more clearly. Thanks.

    And in light of this, I think it is somewhat unfortunate that in the Perl literature accessor generation is so often presented as a prime example of the utility of AUTOLOAD.

    the lowliest monk

      In general, I would expect that almost no one should ever use AUTOLOAD. That's a feature for use when you don't know until call-time whether a given method is going to be valid or not. If you know this at compile time, do your sub generation then. If you know it at db connection time, do it then. Whatever. In general, the time to generate subs is not during the statement you're using it in.

      Consider what happens to the maintenance programmer (or just some debugger program) when a method can't be detected as existing until it has been called at least once. Its ugly and it isn't being nice.

        I see your point, but I find it interesting that one of Perl's standard modules, AutoLoader, is there precisely to support the loading of subs upon first use.

        Which prompts the question: why does Perl actively support such a problematic feature? Two possible explanations come to mind: (a) lazy loading of subs was a bad idea from the start (for the reasons you describe), and future versions of Perl should get rid of it; or (b) there are a few rare instances in which the benefits of lazy loading outweigh its drawbacks, hence Perl supports it.

        If I know anything about Perl culture, then I'd guess that (b) is by far the more likely explanation of the two, and I'm left to imagining what those "few rare instances" may be like. The only situation I can envision in which lazy loading may be desirable (despite its drawbacks) is one in which the possible methods are vastly more numerous than those that are actually used by any application. But this is all theoretical, since I don't recall ever using a module that fit this description.

        Update: Just to be clear: I'm not presenting the existence of AutoLoader or its presence in the core as a veiled argument in favor of anything. I am genuinely interested in the question of why it's in the core in the first place: was it a mistake, or is it there because there are some legitimate (even if rare) uses for it?

        the lowliest monk