[Newbies] Accessors

Blake blake at kingdomrpg.com
Mon Mar 12 06:15:05 UTC 2007

On Sun, 11 Mar 2007 18:46:00 -0800, Jerome Peace  
<peace_the_dreamer at yahoo.com> wrote:

> However:
> myCollection := nil.
> or
> myCollection := #() .
> will clear the collection.

Since I want it empty, not gone, I'm doing this:

myCollection := OrderedCollection new.

> On accessors versus raw IVars. its a matter of
> programmer choice. If the data is hidden from other
> classes it can be handled by using just the iVars
> within the class w/o an accessor.

Yeah, I guess. I've always tried to keep the object as close to a client  
of itself as I can but that's a decent rule of thumb.

> Your probably about ready for Kent Beck's book
> "Smalltalk: best programming pattern practices." Which
> will answer a lot of the questions you are about to
> ask.

I didn't find it that inspiring on a browse, but I'll check it out.

> If you try to do the "simplest thing that might
> possibly work." Then you would probably start with the
> ivars and switch over to using accessors when there
> becomes a need.

I guess that works pretty painlessly.

> Go reread the comment for #removeAll I believe you
> will find it does not do what you wish.

Actually, it does, as long as I create an identity copy of the collection  
to pass as the parm.

> Try:
> myCollection := OrderedCollection new
> 	add: 4
> 	; add: 3
> 	; add: 2
> 	; add: 1
> 	; yourself.
> myCollection removeAll: myCollection  .
> and see what you get. See if you can figure out why.

This looks like something I've seen often in other languages, where the  
iterator ends up missing items because it's changing as it goes. Hard for  
me to believe this is a bug, but that's what it looks like to me.


More information about the Beginners mailing list