[squeak-dev] Re: What is equivalence? (was: The Trunk: Collections-eem.603.mcz)

Chris Muller ma.chris.m at gmail.com
Thu Feb 5 02:38:44 UTC 2015

> IMO that's a bug.   And the bug is that WeakArray species = WeakArray,
> whereas it should be Array.  If one selects/rejects/copies a WeakArray the
> result is more useful if it is strong.  It would be interesting to make the
> change and see what effect it has on the standard test suite.


>> I think the answer is because #= (not any other method, just #=) needs
>> to care about which _implementation_ of the argument which is passed
>> when considering true equivalence to another object.
> IMO the problem is because coming up with general purpose #= implementations
> is hard.  You must have seen the controversy my definition of
> CompiledMethod>>#= has caused over recent years.  #= has evolved a lot since
> Smalltalk-80 as its been more affordable to be cleverer, but that evolution
> also shows that its not absolutely obvious what #= should do; it depends on
> context, and current definitions of #= are general agreements of useful
> behaviour, some of these agreements having been made a long time ago.

Being cleverer in #= feels right but general agreements also feels
right in terms of having dependable contracts.  For example, its
really nice that everyone has "agreed" to include a valid #hash method
when they write an #= method.   We just do it regardless whether we
actually think we will put them in a HashedCollection.

>> I agree we human developers can consider unequal but same-quacking
>> objects interchangeable in our fuzzy minds when we design our
>> applications, and that is powerful, however, *within the system*, I
>> just it needs #= to make implementation-specific distinctions,
>> especially for as base-classes as Array and Dictionary.
> One thing #= should do is accept any object as an argument without error.

Another very good general agreement for equivalence testing.  I agree!  :)

> This wasn't always the case, but Smalltalk was not and never will be
> perfect.  Apart from that, what #= means is something we have to negotiate.
> I don't think my recent changes broke anything.

I don't think anything will be broken.  None of my outboard
SpecialDictionary's implement isDictionary.  It gave me pause to
wonder what it should answer..

>> This seems to be reflected by most of the #= implementations in the
>> system, which check either #class, #species, or #isKindOf:.
> Few of them use isKindOf:.  Some use class or species.  Some use #isFoo.  I
> don't see that #isFoo is worse than #class or #species.  Do you think it is?

Hm.  In any other method besides #=, #isFoo is always better.  In
Dictionary>>#=, it will perform better, it probably won't break
anything even external.  So, definitely not worse.  :)  Just making
sure when changing such a method as Dictionary>>#=...

 - Chris

More information about the Squeak-dev mailing list