Dictionaries broken in 3.9a

Andreas Raab andreas.raab at gmx.de
Tue Sep 20 07:58:08 UTC 2005


Chris Muller wrote:
> Sorry if my "fix" disrupted you Andreas, I guess I fixed the wrong thing.  
> But while Dictionary's appear able to contain nil keys afterall, what about
> WeakKeyDictionarys?  As their keys are garbage-collected and converted to nil
> it would be unpredictable, at best.

Agreed, yet I could still see some reasons to do it. I think the key 
question is: What exactly are you trying to fix? There was some 
mentioning of "dictionaries cannot have nil keys" but no argument has 
ever been made why this should be so. It's like saying Arrays cannot 
contain "0" - what would be the point of that? ;-)

Also, I think it's well-understood that users of weak dictionaries may 
get some unpredictable behavior as the keys may go away at any time. If 
you use a weak key dictionary you really should understand that this may 
happen and guard appropriately. If that's not doable, then maybe we 
should stop having those be (subclasses of) collections and make them 
something completely different.

> Therefore, what do you think of my overriding #associationsDo: in
> WeakKeyDictionary, which was the real crux of my original fix back
 > in June of '04?  I should have just stopped with this..

But then again, what for? What is actually broken? I still haven't seen 
anything that could be considered a bug.

> Incidentally, there may be a few special side-effects to having a nil key in a
> regular Dictionary which could bite at some point.  For example:
> 
>   (Dictionary new at: nil put: 'nil') keys

That's an interesting point. The best cure would probably to fix sets so 
they can contain nil entries.

Cheers,
   - Andreas




More information about the Squeak-dev mailing list