[Newbies] ordinary #hash and Dictionary [was: Recap: How to empty a collection]

Klaus D. Witzel klaus.witzel at cobss.com
Wed Feb 20 15:44:33 UTC 2008


On Wed, 20 Feb 2008 00:59:57 +0100, nicolas cellier wrote:

...
> I see, become: does exchange #identityHash, and that makes our  
> IdentityDictionary work, god thanks, but there is no such provision for  
> ordinary #hash and Dictionary...

But there are sufficient provisions in place, since Smalltalk-80, and most  
Dictionary users know about them :)

> However, there are plenty of ordinary things that would have the same  
> result:
>
> | key1 key2 dic |
> key1 := 'abc' copy.
> key2 := 'abd' copy.
> dic := Dictionary new.
> dic at: key1 put: 1.
> dic at: key2 put: 2.
> key1 at: 1 put: $z.

  dic rehash "synopsis: re-establish hash invariants, if any ".

> {dic includesKey: key1.
> dic keys includes: key1.}
>
> So i propose newbies do not use #at:put: considering the danger about  
> Dictionary not finding their keys...

There's no danger with Dictionary not finding its keys, unless you  
yourself do not follow the protocol.

Smalltalk has no such problems; developers use #rehash after they changed  
the #= of keys in Set and subclasses; and please, don't tell the newcomers  
the contrary :)

> That's too much.

No not too much; in other languages (especially the "popular" ones) you  
are not even allowed to change you strings-now *that* is too much ;-)

But in Smalltalk you are supported, right from the beginning; happy  
Smalltalking everybody :)

/Klaus



More information about the Beginners mailing list