Need feedback on simple idea

Jon Hylands jon at huv.com
Thu Apr 10 23:52:47 UTC 2003


On Thu, 10 Apr 2003 19:13:37 +0500 , Adam Spitz
<aspitz at student.math.uwaterloo.ca> wrote:

> Interesting. When do you use methods with the same names as instance
> variables? The only time I can think of is when I want to do some sort
> of lazy initialization thing, but then I think that the code
> communicates better if I call the variable something like
> "cachedWobulator" instead of just "wobulator".

Many times. I often choose instance variable names based on what they
represent, not how I choose to implement the state.

Perfect example: contents in Streams. The instance variable is private, the
accessing method provides a modified representation of the instance
variable.

> I like the idea that an object is just something that responds to
> messages; it bothers me, at some weird aesthetic level, that accessing
> instance variables is different. At a more practical level, it bothers
> me that I should have to think about whether to use "accessor methods"
> or not. And at a completely superficial level, it really bugs me to see
> the word "self" spewed all over my code. ;)

The point is, you have to think about code from two perspectives.

From an implementor's point of view, instance variable accessing is just
like any other variable accessable -- temp variables, arguments, class
variables, globals. Why should they be any different?

From a user's point of view, instance variables don't exist. Very simple,
very consistent.

Later,
Jon

--------------------------------------------------------------
   Jon Hylands      Jon at huv.com      http://www.huv.com/jon

  Project: Micro Seeker (Micro Autonomous Underwater Vehicle)
           http://www.huv.com



More information about the Squeak-dev mailing list