Please use accessors!

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


> ** Original Sender: Andres Valloud <sqrmax at cvtci.com.ar>
> ** Original Date: Sun, 01 Aug 1999 14:07:34 -0700
> Hi.
> 
> > 7. Whether Andres was wrong or right about direct
> > instance variable access, it was not cool to come down
> > on him like a ton of bricks.  Andres, on the other hand,
> > should have simply questioned why the instance variables
> > were not being accessed directly, instead of boldly asserting
> > they should be.
> 
> I'd like to clarify something... the subject of my original mail is
> "[Interval Problem] my 2 cents". I was hoping that my assertion would be
> clearly restricted to the Interval fix being discussed. I made the
> assertion based on the style already used in the coding of Interval,
> that is, no accessors. Then... is this a bold assertion? 
> 
> "I think it would be a good idea to remove the self sends..."
> 
> I'd rather say that a bold assertion would be more like
> 
> "Self sends must be removed..."
> 
> but I could be wrong since English is my second language.

Andres:

Humility will get you everywhere :-).

I don't think, or speak, in stark Aristotelian terms.  For example,
I don't consider boldness to be a binary property, where an action
is either bold or not bold.  There are degrees of boldness, a 
continuum of boldness, if you will.  Your statement was less
bold than some of your critics, but more bold than my suggestion
of simply asking why.  It was obviously too bold for some of
the gentle readers of this list (rightly or wrongly) :-).  

On the other hand, wasn't Socrates done in just by asking 
questions? So even that artifice may not protect you :-)

I have noticed that non-native speakers of any language tend
to take statements in their non-native language more literally
than native speakers do.  A native speaker (of whatever
language) will likely take statements starting with "I think it
would be a good idea to.." as simply a polite way of saying
"It is a good idea to..." (especially when the "polite" form
is used so frequently that it becomes an idiom or euphemism).
That's how I interpreted your comment, without concsiously
thinking about it.  So I apologize for reading more boldness
into your assertion than was perhaps intended.

There are those who would argue, of course, that any assertion,
no matter how politely phrased, that one should access iVars
directly instead of using accessors is pretty bold.   I think
recent history demonstrates this.

But permit me to be so bold as to say that, yes, it's not only
OK to access the instance variables of Interval directly, it's
probably better, since I see no justification for lazily initializing 
any of the instance variables.  Using mutators to set the 
values of the variables is another matter,  however.  

I suppose one might want to have an AbstractInterval 
(someday), with BasicInterval as a subclass that has the
standard slots (start, stop, step), and another subclass that 
acts as an adapter or decorator of some other object, deriving 
the start, step and stop values from the adapted (decorated) 
object.  But such a redesign can be accomplished easily 
enough when found to be necessary.  This is one case where 
I would value simplicity more highly than generality, at least 
as far as the standard library classes are concerned.  One
needs to strike a reasonable balance between generality,
abstraction, concreteness and doing real, specific work
within a finite budget of development time, execution time 
and computer memory usage.

--Alan





More information about the Squeak-dev mailing list