develooper Front page | perl.perl5.porters | Postings from March 2011

Re: Revising Perl's OO docs - a new OO tutorial

Thread Previous | Thread Next
Ricardo Signes
March 7, 2011 13:21
Re: Revising Perl's OO docs - a new OO tutorial
Message ID:
* Chris Prather <> [2011-03-07T15:21:44]
> On Sun, Mar 6, 2011 at 9:34 PM, Father Chrysostomos <> wrote:
> > If we do add object attributes to Perl, it would be very nice if we could
> > use ‘$obj->attr = $foo’ syntax, instead of $obj->attr($foo), which is
> > currently widely used mainly because the former is so hard to do (that can
> > change, of course).
> >
> It's my (not-so-humble) opinion this is a horrible idea. It violates
> encapsulation and confuses the behavior with state in a way that will
> only lead to *more* confusion down the line.

He didn't say that it would have to be lvalue subs.

Look at how Ruby does this:  you provide an "attr=" method that is called on
assignment, so you are not violating encapsulation or confusing behavior with
state.  It's sugar for a normal method call, which can have any behavior you
want and mutates whatever state system it wants however it wants.

I'm not saying that I want ->attr=$x, only that you are arguing against
something that needn't be true.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About