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

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

Thread Previous | Thread Next
From:
Ricardo Signes
Date:
March 7, 2011 13:21
Subject:
Re: Revising Perl's OO docs - a new OO tutorial
Message ID:
20110307212103.GA8413@cancer.codesimply.com
* Chris Prather <chris@prather.org> [2011-03-07T15:21:44]
> On Sun, Mar 6, 2011 at 9:34 PM, Father Chrysostomos <sprout@cpan.org> 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.

-- 
rjbs

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About