in reply to Re: Perl OO and accessors
in thread Perl OO and accessors
Within the class package, accessors and mutators are heavily used for typo avoidance -- or rather, compile-time typo checking.Considering that Perl does look up of methods at run-time, what checking is done at compile-time?
(And yes, inside-out objects address some of that, with yet other tradeoffs.)Nowadays, I usually use inside-out objects, and that means I don't write accessor all that often. I don't use objects if I want C-type structs, hashes will do fine in that case. For other cases I only provide methods to the outside world for those cases where the outside world might want to inspect (or set) some state of the object. This may be an accessor, but the outside world neither knows, nor has the need to know.
I never use accessors to let a class get at its own data. IMO, there's no point in adding the overhead of calling a method to get a value from a hash, and I prefer the compile-time errors I get from making typos when accessing the data instead of the run-time errors when typoing a method name.
For me, the existance of an accessor means that I intended the outside world to set, or look at a state. And that I hence should be careful when redoing the internals.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl OO and accessors
by dragonchild (Archbishop) on Nov 29, 2005 at 12:54 UTC | |
by xdg (Monsignor) on Nov 29, 2005 at 13:26 UTC | |
by chromatic (Archbishop) on Nov 29, 2005 at 19:27 UTC | |
by herveus (Prior) on Nov 29, 2005 at 20:21 UTC | |
by Perl Mouse (Chaplain) on Nov 29, 2005 at 13:10 UTC |