Open seandenigris opened 2 years ago
A. Valloud wrote a whole book about this (and more)! His hashing book, to my layperson's ears, summarizes:
`#=` must mean "what hashed collections expect it to be".
This implies that there will be as few collisions as possible. The fact that it took a whole book hints that the situation is much more complicated than #bitXor:
-ing together instVars, as is commonly recommended.
After seeing all the pitfalls, I would add an additional rule: avoid redefining #=
unless you a) really know what you're doing and b) need the optimization that hashed collections offer. For example, I used to use Set
a lot, but now I wrap a non-hashed collection and override add to prevent duplicate elements.
Incorporate #21 (closing because it's basically a duplicate)
Asked on Pharo Dev:
Anyone know of a book that goes in depth explaining
#=
?I've always wondered what "equal" is supposed to mean.
For example, if I have two objects representing the same person, but one has their webpage cached as state, they represent the same entity, and are interchangeable in many contexts, but also have a difference that may be important in other contexts.
Is “equal” whatever you say it is in your domain, or is it a Smalltalk object system concept? If the latter, what is the exact expectation?
From @jgfoster:
From @nicolas-cellier-aka-nice: