Eliminating assignments and variable syntax (accessors)

Alan Lovejoy sourcery at pacbell.net
Mon Aug 2 23:20:00 UTC 1999


> ** Original Sender: Marcel Weiher <marcel at system.de>
> > From: Stefan Matthias Aust <sma at netsurf.de>
> > Resent-Sender: squeak-request at cs.uiuc.edu
> >
> > >Variables can be kept somewhat
> > >private by not creating accessors for them.  Decisions to use direct   
> > >variable access are localized, not spread over all the code that   
> > >makes use of the variable.
> >
> > I don't understand the last point?  How can you restrict the  
> access by not
> > providing accessor methods if this would also mean that nobody can  
> access
> > them. As I understood, you wanted to get rid of ":=" and direct  
> variable
> > access altogether.  Without (public-accessable) methods you cannot use 
> > these variables...
> 
> Well, I guess that is the part that got sort of lost in the noise:   
> If there are no accessors, the compiler compiles 'accessor/mutator'  
> message sends to self as direct variable access.  Therefore, the  
> object itself can access its own instance variables (and local  
> variables) even if the accessors are not defined, whereas in SELF  
> there is an automatic definition of accessors.
> 
> Crucial difference.

Yes, it is that.

If one decides only at compile time whether "self foo" is a message 
send or a variable access, one must then recompile all methods that access
the iVar foo as soon as an accessor is introduced.  A worse problem
is what to do when an accessor is introduced **in a subclass**.
Should that change the meaning of code in a superclass, or not?

Worse, suppose the accessor does lazy initialization, but there are
references to the iVar where lazy initialization would be either
incorrect or at least undesirable?

--Alan





More information about the Squeak-dev mailing list