Tom Sawyer wrote:

>On Fri, 2002-08-09 at 13:30, Dave Thomas wrote:
>  
>
>>This is an interesting issue: should internal users go via the setter
>>method or access the instance variable directly. Clearly it depends on
>>the circumstances, but I often find myself writing accessors that do
>>things such as lazy evaluation, or which set dirty flags for
>>persistent objects, and where I really do need to go via the method
>>form. For those times, it's nice to have a shortcut, but it isn't
>>something I'd fight hard for... :)
>>    
>>
>
>i'd like to refocus on this aspect of the ambiguity thread. from what's
>been posted thus far on the topic, it would seem it is best to always
>use the accessor methods when they exist. i hanker to bet many of us do
>not do this. and i think this has to do with the fact that the
>...
>
It has been asserted.  I don't think that it has been generally agreed. 
 Within a class accessor values may be either used or not used depending 
on why they were created, and what the cost of using them is.  Partially 
also on how large the class is, whether the change is being made as a 
part of the same declaration that was the original class declaration, etc.

Generally, if the class variable is set or read at a distance, either 
logical or physical, from the original declaration, then accessors 
should be used, and this can be sufficient reason to create them.  Also 
generally if there is excessive cost to using them, then they should be 
avoided.  Neither of these factors are all-or-nothing factors, e.g. if 
they are private variables, there may be a disinclination to create 
accessors even if they are accessed at a large distance from the 
original declaration.  And if they are sufficiently expensive to use, 
there will also be a great disinclination to use them unless they are 
really needed.

These arguments are independant of the stylistic costs, but an easily 
used syntax encourages the use of a feature even when it is 
inappropriate, and a difficult syntax discourages the use of a feature 
even when it is appropriate.  So the features that are expected to be 
more used should have the shorter/easier forms.  (See Zipf's law.)

-- 
-- Charles Hixson
Gnu software that is free,
The best is yet to be.