[Newbies] Re: Recap: How to empty a collection

nicolas cellier ncellier at ifrance.com
Tue Feb 19 23:59:57 UTC 2008


Blake a écrit :
> On Tue, 19 Feb 2008 15:08:56 -0800, nicolas cellier 
> <ncellier at ifrance.com> wrote:
> 
>> Blake a écrit :
>>
>>> Well, from what I was reading, "slow" and "smells" is putting it too 
>>> mildly. It sounds like it can corrupt your image, i.e., leave you 
>>> with non-working objects in unexpected places. I wouldn't even 
>>> mention it.
>>
>> Huh?
>> Have a proof of what you wrote?
> 
> Proof? None at all. I just have this, by Gulik:
> 
> "[become:] doesn't work fine. It breaks code that relies on hashes; 
> specifically, a Dictionary elsewhere in yo ur image can start acting 
> screwy if you do a #become: variant that doesn't preserve an object's 
> hash. See #becomeForward>>copyHash:. You would then also be relying on a 
> Squeakish behaviour and your code would become less portable across Sm 
> alltalk dialects.
> 

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...

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 includesKey: key1.
dic keys includes: key1.}

So i propose newbies do not use #at:put: considering the danger about 
Dictionary not finding their keys...
That's too much.

becomeForward: is squeakish, but the thread was about Squeak 
implementation of a core library...
A rule is to use becomeForward: only with a just created object as argument.
But right, that's just too much for this thread.

> They are also a fantastic way to introduce bugs of various sorts, and 
> can even cause an image to crash (as in, stack trace and exit to the 
> OS). Say, for example, that one of the arguments you pass is accidently 
> nil, true or false? Your image would c ontinue working... for a while."
> 
> Does this sound like something a newbie should use? No, it does not.
> 
>     ===Blake===

OK, good lesson, thank you.
Handle with care.
Try finding better patterns.
Protect usage (don't use with an unknow argument).
It smells.
I agree.
But don't pretend it's broken please.

Anyway, why do you think all code is accessible in Smalltalk?
In the spirit, nothing is to be hidden from newbies eyes.
Yes I know, maybe some code should



More information about the Beginners mailing list