On 4/20/04 4:08 PM, Aaron Sherman wrote: > On Tue, 2004-04-20 at 15:40, John Siracusa wrote: >> On 4/20/04 2:37 PM, Larry Wall wrote: >>> It's wrong to introduce a fundamental asymmetry that breaks the contract >>> that an accessor can be used as a variable. >> >> Er, I think we have different definitions of "accessor." I'm perfectly >> happy to never allow anyone to do $obj.foo = whatever. I just don't want to >> write trivial methods that get and set an attribute behind the scenes. > > Eh? Why would you never allow anyone to use a simple syntax? > > $oldfoo = $obj.foo; > $obj.foo = 1; > > What's the problem here?
The problem is when foo() becomes a complex method some time in the future. It's some work to "upgrade" foo from a simple "is rw" attribute to a full-blown method while also maintaining the end user's ability to say $obj.foo = whatever. > What Larry's trying to get at is that: > > $status = $thread_shared_data.status(lock=>1); > > could be defined as a multi which gets the value of the status variable, > but also asserts that thread synchronization or some form of threadsafe > locking must be performed. You're not SETTING status, you're reading it, > but you are passing parameters to the read accessor. How do you do that > if parameters force a write? If that's your situation, you can make status() a "getter" only and add a set_status() "setter." Or you could make foo() say "if I get a single scalar (i.e. non-pair) arg, then set, otherwise get with options." But maybe that's as evil to some people as writing trivial get/set accessors is to me :) -John