C
Chris Uppal
Patricia Shanahan wrote:
[me:]
Only in the minimal sense that it abides by its contract. It not, however,
useable for anything; therefore it only exists (or should only exist) as a
placeholder for a method which the author assumes will not be needed. But
that's a major risk -- sooner or later someone else is likely[*] to start using
these things in HashTables, and then they get poor performance without knowing
why (or perhaps even without realising that they are getting unecessarily poor
performance). If the assumption is that the method is only a placeholder, then
it would be much safer (as I said) to throw an unchecked exception.
If any programmer /I/ worked with was in the habit of leaving these little
timebombs ticking away in the codebase, then I'd be inclined to throw a Very
Serious Wobbly.
What you think of a programmer who habitually wrote:
void toString() { return ""; }
? Yet that's a damn sight safer (and no less "reasonable") than always
returning zero from hashCode().
As an aside, profiling is not a good tool for recognising or diagnosing poor
hashing functions. And, although it is a reasonable tool for confirming that a
non-too-special hash function is "good enough", even that is somewhat unsafe
unless you know that your test data is representative of real world data /in
the way it interacts with the hash/.
-- chris
[*] "likely" assuming normal operation of Sod's Law.
[me:]
It is a functionally correct hashCode.
Only in the minimal sense that it abides by its contract. It not, however,
useable for anything; therefore it only exists (or should only exist) as a
placeholder for a method which the author assumes will not be needed. But
that's a major risk -- sooner or later someone else is likely[*] to start using
these things in HashTables, and then they get poor performance without knowing
why (or perhaps even without realising that they are getting unecessarily poor
performance). If the assumption is that the method is only a placeholder, then
it would be much safer (as I said) to throw an unchecked exception.
If any programmer /I/ worked with was in the habit of leaving these little
timebombs ticking away in the codebase, then I'd be inclined to throw a Very
Serious Wobbly.
What you think of a programmer who habitually wrote:
void toString() { return ""; }
? Yet that's a damn sight safer (and no less "reasonable") than always
returning zero from hashCode().
I assume that if Mark found poor hash table performance during
profiling,
As an aside, profiling is not a good tool for recognising or diagnosing poor
hashing functions. And, although it is a reasonable tool for confirming that a
non-too-special hash function is "good enough", even that is somewhat unsafe
unless you know that your test data is representative of real world data /in
the way it interacts with the hash/.
-- chris
[*] "likely" assuming normal operation of Sod's Law.