On Tue, 16 Sep 2003, Steve Purkis wrote:

> On Tuesday, September 16, 2003, at 02:53  pm, Andy Wardley wrote:

> > On the other hand, I find it quite acceptable to have get_foo()
> > that returns the foo, and set_foo($new_value) which sets the
> > new value for foo and returns the object.  In this case, the
> > action is explicit in the method name.
> >
> >   # this is when chaining is good, IMHO
> >   $obj->set_foo(10)->set_bar(20)->set_baz(30);
> >
> >> Question is: what style should be the default?  I'm not looking for a
> >> debate here,
> [...]
> But you bring up some points I've gotta answer -- first off, 'set_' &
> 'get_' don't seem to be too popular (laziness?) so unless people prove
> me wrong here, they're out for accessors.pm. [1]
> [...]
> [1] As a complete aside, I don't think 'get_' and 'set_' are bad ideas.
>   There's no reason reason someone couldn't write 'accessors::setget',
> or 'getters' and 'setters' pragmas.  Michael Schwern recently pointed
> me to Ruby's 'attr_reader' and 'attr_writer' shortcuts - see
> http://www.rubycentral.com/book/tut_classes.html

+1 for getter/setters then.

I resisted posting about it for fear of starting a debate, but
apparently Andy couldn't help himself... ;--)

I often have getters, or things that really look like getters at least,
that are much happier when passed parameters. You can't do that with the
usual Perl idiom of a single method. lvalues can be a solution, but do not
work in all cases.

--
Michel Rodriguez
Perl & XML
http://www.xmltwig.com


Reply via email to