Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!portc01.blue.aol.com!news-peer.gsl.net!news.gsl.net!news.mathworks.com!news.pbi.net!samba.rahul.net!rahul.net!a2i!hustle.rahul.net!rahul.net!a2i!news.clark.net!noos.hooked.net!news.scruz.net!cruzio.com!news
From: "James A. Sawyer" <jas@cruzio.com>
Subject: Re: Accessing instance variables
Content-Type: text/plain; charset=us-ascii
To: dnsdebro@aol.com
Sender: news@cruzio.com (System Administrator)
Content-Transfer-Encoding: 7bit
Organization: Cruzio Community Networking System, Santa Cruz, CA
Message-ID: <328A613C.392@cruzio.com>
References: <3289FC37.35DA@csu.edu.au> <19961113182500.NAA27957@ladder01.news.aol.com>
X-Mailer: Mozilla 2.0 (Win16; U)
Mime-Version: 1.0
Cc: jas@cruzio.com
X-Nntp-Posting-Host: kelp132.cruzio.com
Date: Thu, 14 Nov 1996 00:01:00 GMT
Lines: 63

> Phillip Swain wrote: [I'm paraphrasing - JAS]
> 
> >There seems to be two different arguments.
> >
> >If you want to access an instance variable 
> >  from within the enclosing object you can
> >    1) access them directly
> >         (argument: Smalltalk base code does this)
> >    2) Access them indirectly through getters/setters.
> >         (argument: easier to change)

dnsdebro@aol.com wrote:
> 
> While I'm in the object I access the instance variables directly
> ...it's faster...(Am I wrong?)
> 
> While outside the object I do use the "getter" and "setter" methods for
> public variables.
>
> ...if I know that my object will not be used visually I don't use these
> methods unless I'm outside the class.
> 
> Am I wrong in my analogy?  Please someone let me know.
> 
> Thanks,
> Dennis Debro
> Smalltalker for KHS

You are right that direct access is faster, but this
is not the proper concern until you have (in order)
  1) a working product
  2) which is too slow, according to requirements
  3) and profiling the code shows that
     switching back to direct access will
     increase speed enough to meet requirements.
This is not an impossible sequence of occurances,
but it is highly unlikely for most products.

Hence you are (usually) purchasing unnecessary,
low value optimization at the expense of very high 
value flexibility/maintainability.

Getters/Setters could be used for accessing
public variables from outside an object, but
should not be.

Reason: Encapsulation.

	If an object needs the value of a variable,
          it ought to own the variable.
        If some other object owns the variable,
          it ought to own the processing that
          goes with it.
	(My prior post in this thread has more detail...)

Your reasoning is incomplete, but shared by many, which is 
why I believe it is important to nail this one down early,
in beginning classes on Smalltalk/OOD, whenever possible.

Regards,

-jim

