[ENH] Refactored equality operators.

Brent.Pinkney at reuters.com Brent.Pinkney at reuters.com
Tue Jul 10 19:19:06 UTC 2001


Hi,

This morning I got a message from Ross Boylan noting that my new DateAndTime classes do not play nicely with projects because loading a project into an image tests a collection for inclusion  (somewhere), which in turn compares a DateAndTime instances to a Block.

This results in a nasty MessageNotUnderstood and a debugger. to convince yourself, evaluate:

     Date today = 123.

Inspection of 3.1 at changeset 4173 shows that there are

60   implementations of #=
4    implementations of #~=

3746 senders of #=
445  senders of #~=

Inspection of a few of these shows that some go to extraordinary lengths to protect themselves from unexpected comparisons whilst others are quite cavalier.

Some of the well protected code is pretty inelegant, checking classes, species, respondsTo, etc before performing the comparison. My suspicion is that this paranoia is almost never required. Unfortunately, as Ross has discovered, it is essential.

Solution
=======
I propose we introduce #basicEquals: and #basicNotEquals: to supplement the #= and =~#. Developers overload this method and code with gay abandon.

Introduce new notification class Uncomparable which has as its, default action to return false.

Then refactor Object>>#= to catch any DNUs and re-signal them as Uncomparables. ie

     Object>>#= anObject

          ^[ self basicEquals: anObject ] on: MessageNotUnderstood do: [ :ex | Uncomparable signal ]

Benefits
=======
Say it once, say it well.
Showcases the benefits of resumable exceptions.

File in
=====
Attached are two change sets.
Filein in PreBasicEquality before BasicEquality.

Basically these rename the overloaded equality operators to the new #basicEquals:/#basicNotEquals: stuff.
To better the chances of a smooth migration, a subsequent changeset (PostBasicEquality) will be provided (assuming there is interest) which eliminates the now redundant tests.

I have tested this in 3.1alpha with changeset 4173. All appears ok.

Now try

     Date today = 123.

Very posh stuff this Smalltalk.

Cheers

Brent

(See attached file: BasicEquality.11.cs)(See attached file: PreBasicEquality.1.cs)






-----------------------------------------------------------------
        Visit our Internet site at http://www.reuters.com

Any views expressed in this message are those of  the  individual
sender,  except  where  the sender specifically states them to be
the views of Reuters Ltd.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BasicEquality.11.cs
Type: application/octet-stream
Size: 22209 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20010710/c1afb628/BasicEquality.11.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PreBasicEquality.1.cs
Type: application/octet-stream
Size: 329 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20010710/c1afb628/PreBasicEquality.1.obj


More information about the Squeak-dev mailing list