in reply to Modules for autogenerating accessor/mutator methods

I'll even add to your question: is there any reason not to write accessors/mutators ourself?
  • Comment on Re: Modules for autogenerating accessor/mutator methods

Replies are listed 'Best First'.
Re^2: Modules for autogenerating accessor/mutator methods
by tlm (Prior) on Jun 04, 2005 at 21:33 UTC
      Hey, that was my answer! However, these modules exist and are definitely being used. Class::DBI is a prime example. I really don't get much out of writing simple accessors/mutators. If they get more complicated, I would of course like to have the Module move over and facilitate my creating a custom method, which most seem to offer as an option. I think the question still stands as to which, if any, is "better" than the next (or what less-than-obvious advantages exist in one versus the next).

      Sean
      Really I'm not sure. An accessor/mutator is often very simple, so where is laziness? writing the quick'n'dirty one that "just works" or use a complex module that provides complex options and try to learn how it works --and may bite?

        I hear you; I have not found an accessor-generating module that was worth the trouble. But to be fair, I haven't looked too hard since I don't do much module writing (most of my coding is scripts), so my needs in this regard are very modest. For the few modules I write (which are usually relatively simple) I get by with AUTOLOAD, which I still consider lazier than typing out a dozen accessors, even if the "typing" amounts to as little as a brief exercise in cutting and pasting.

        the lowliest monk

Re^2: Modules for autogenerating accessor/mutator methods
by brian_d_foy (Abbot) on Jun 05, 2005 at 04:14 UTC

    When a lot ( > 2 ) of your subroutines have the exact same code, why type it more than once? :)

    Other than that, some things generate lots and lots of accessors. Writing some code to automatically generate them all means less typing and a single point of maintenance when you decide you need to change them all.

    --
    brian d foy <brian@stonehenge.com>
Re^2: Modules for autogenerating accessor/mutator methods
by magog (Beadle) on Jun 05, 2005 at 06:40 UTC

    I'll even add to your question: is there any reason not to write accessors/mutators ourself?

    Because then we would also have to write tests for them.

    Michael