[squeak-dev] true hash

Bert Freudenberg bert at freudenbergs.de
Wed May 9 20:36:46 UTC 2012


On 09.05.2012, at 22:19, Chris Muller wrote:

>>> Where do true, false and nil obtain their hash value?  They inherit
>>> #hash from Object, so it is their identityHash, but I noticed this is
>>> consistent between images -- how?  It's great, but is there any danger
>>> of that value ever changing?  That would be bad..
>> 
>> 
>> The identity hash bits are stored in each object's header. And since true, false, nil are the same decades old instances, their hash did not change.
>> 
>> Depending on what the SystemTracer does, it may be different in an image derived by that though. E.g. you may want to check a 64 bit image.
> 
> So, just in thinking about it -- that is a VERY distant dependency
> that could manifest as a bug way up in at an app-level in production.
> Because no SUnit test would be able to catch it, and when trying to
> debug it in production, invariably someone with the "classic" hashes
> not be able to reproduce the problem..  Hopefully it would only be a
> "lookup" problem but what if it was in the context of an
> #at:ifAbsentPut:?  What a nightmare!
> 
> So, it would seem a good idea to override #hash to return their
> current value as a fixed constant.
> 
> Thoughts?

-1

Why would you depend on the exact value of the identity hash?

When writing a new image and the identity hash changed, then obviously all dictionaries would have to be rehashed. Seems like a non-issue to me.

Besides, YAGNI. If and when you need that you could still add these methods. Though you wont ;^)

- Bert -




More information about the Squeak-dev mailing list