[Python-3000] callable()

Andrew Koenig ark-mlist at att.net
Tue Jul 25 15:10:18 CEST 2006


> All of which is a long-winded way of saying "calculation of an object hash
> should be both cheap and idempotent" :)

Actually, I disagree -- I don't see why there's anything wrong with a hash
being expensive to calculate the first time you do it.

For example, consider a string type in which the hash algorithm examines
every character of the string.  Those characters had to get there in the
first place, so the total time spent computing the hash is no more than a
constant multiple of the time spent creating the string.  Nevertheless, it
seems reasonable to me to defer the effort of computing the hash until you
know that it's needed -- that is, until the first time you are asked to
compute the hash.

If you're going to say that computing the hash isn't expensive compared with
dealing with the string itself, then I'll reply that computing the hash of a
CD isn't expensive either, if you compare it with dealing with the CD itself
:-)




More information about the Python-3000 mailing list