[BUG] Dictionary equality test

Chris Muller afunkyobject at yahoo.com
Fri Jun 14 18:43:57 UTC 2002


I find it disappointing that = was implemented so liberally in Squeak.  =
should only be implemented when there is absolutely NO ambiguity in the meaning
of = with respect to that class.  In most cases, we see that only classes that
represent a measurable or "magnitudinal" value of some kind, (i.e., Number,
Color, Date, Pitch, etc.) are suitable candidates.

Sets, Dictionaries and Customers are very poor candidates.  The very fact that
we have posted our different interpretations of how we think Dictionary>>=
should behave proves it.

Because of this, Dictionary>>= should inherit the identity-check from Object>>=
and you should use the more intention-revealing method, includesAllOf:.

Unfortunately, includesAllOf: "incorrect" for Bags in my view, because it
doesn't account for the occurrencesOf: each instance, it only requires one. 
Yet another example of the importance of thinking about the namespace we
consume when we extend a base class.

Incidentally, there are other GOOD reasons to avoid using = besides this
semantic one.  Consider the following:

1.  slower execution performance for comparisons, adding and finding in hashed
collections.

2.  slower development performance: implementing = also requires that you
implement #hash.  Not doing so can cause some tricky bugs for less-experienced
Squeakers.

3.  Nightmare bugs:  any time you change an objects attribute that participates
in the determination of equality (and, thus, the determination of its hash),
every hashed collection that references that object must be rehashed.  This can
be a nightmare to debug, even for experienced developers, because it isn't
always easy to know all of the hashed collections that need to be rehashed.

4.  The cost of class schema changes is increased.  When you add a variable to
a class, you have to remember to evaluate the = and hash methods.

5.  Finally, it encourages relational "data" thinking instead of object
thinking where Flyweights are part of everyday life.  A system that does not
share objects, (but instead creates multiple instances with the same "values"
populated in its variables) will consume a lot more memory than one that can
properly share.


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



More information about the Squeak-dev mailing list