Newsgroups: comp.lang.perl,comp.lang.tcl,comp.lang.python,comp.lang.scheme,comp.lang.misc,comp.object
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!news.alpha.net!uwm.edu!caen!hearst.acc.Virginia.EDU!murdoch!usenet
From: "Steven D. Majewski" <sdm7g@Virginia.EDU>
Subject: "magic"  instance variables (was: Comparing syntaxes (was: What Language...))
In-Reply-To: <39mq9a$930@csnews.cs.Colorado.EDU>
X-Sender: sdm7g@elvis.med.Virginia.EDU
Content-Type: TEXT/PLAIN; charset=US-ASCII
Message-ID: <Pine.A32.3.90.941108012326.18486B-100000@elvis.med.Virginia.EDU>
To: Tom Christiansen <tchrist@mox.perl.com>
Sender: usenet@murdoch.acc.Virginia.EDU
Organization: University of Virginia
Mime-Version: 1.0
Date: Tue, 8 Nov 1994 06:49:37 GMT
Lines: 88
Xref: glinda.oz.cs.cmu.edu comp.lang.perl:38276 comp.lang.tcl:21508 comp.lang.python:2474 comp.lang.scheme:11047 comp.lang.misc:18889 comp.object:22402

On 8 Nov 1994, Tom Christiansen wrote:

> :-> In comp.lang.perl, jdonham@hadron.us.oracle.com (Jake Donham) writes:
> :    Tom> Of course, in perl, the x, i, and j variables might all
> :    Tom> actually be tied to secret little package functions, making
> :    Tom> it easier to implement
> :
> :    Tom>     print $his_host{"load average"};
> :
> :    Tom> in a straightforward way:the his_host hash table gets bound
> :    Tom> to some clever little rpc fetcher or SNMP thing.
> :
> :Yikes. Doesn't it make you nervous that simply by referencing a
> :variable all manner of unknown things could happen? Computationally
> :expensive procedures could be called, global variables could be
> :modified--this is not going to help debugging.
> :
> :We're used to procedures not being referentially transparent (and a
> :lot of people aren't happy with that) but referentially opaque
> :variables are an accident waiting to happen. This (mis-)feature has a
> :lot of "gee-whiz" value but the potential for misuse is large.
> :
> :Jake
> :
> :(I'll admit my Scheme bigotry, but this is just one more thing to
> :dislike about Perl.)
> 
> Huh?  It's phenomenally powerful.  I suppose that you dislike the fact 
> that you can map a hash table in memory to one on disk (via dbm)?
> That's just one example of its use.  The SNMP example hasn't to my 
> knowledge been implemented, but it could be.
> 
> You could have something like:
> 
>     $current_nice_value = -20;
> 
> automatically do the right thing by making the setpriority system call on 
> systems that support it.
> 
 [ ... ] 
> I really think you're really selling this powerful method short.  It is an
> enabling mechanism object abstraction to high degree.  Are you sure you've
> really thought about it a lot?

We had some discussion about just this sort of idiom  at the
NIST Python workshop. We were discussing the design of GUI APIs,
and the pro and cons of:

   oldbg = window.background 
   window.background = "red" 

vs. the more procedural looking:

   oldbg = window.getbg()
   window.setbg( "red" ) 

Some of us (including a few with Smalltalk and other OO language 
experience ) justified the first on the grounds that the OBJECT 
whose attribute was being set was a window, and there was nothing
"magical" about the fact that a hidden procedure was required to
make that change in the object visible. The side effect of assigning
"red" to the windows background attribute IS supposed to be to 
actually change the visible attribute of a visible window. 

  Of course, the others objected on the grounds that we were hiding
the fact that a procedure call was necessary. 

This appears to be a OO vs a procedural oriented POV difference.
From the OO POV, there is nothing at all wrong with abstracting
OUT the presence or absence of procedure calls to implement
side effects. Assignment is just a change of state. If a prodecure
call is required to implement that change of state, then that is
just an implementation detail. 


I would also note that Python has other hidden procedure calls.
"sequence[i]" may just happen to translate into a call to 
"sequence.__getitem__( i )" , and there is now a facility 
to cause any access to a classes instance variables trap to
a method call.

[ Heck! Tom hadn't nearly enough newgroups on the distribution, I'ld
 better tack on comp.object too, just in case! :-) ]


-- Steve Majewski       (804-982-0831)      <sdm7g@Virginia.EDU> --
-- UVA Department of Molecular Physiology and Biological Physics --
-- Box 449 Health Science Center        Charlottesville,VA 22908 --
