[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]

inheritance abuse

Clearly the right solution is to have a mixin that EQ classes
multiply-inherit from that implements isEqual and hash using identity

Do objects move about in memory?  If so, then identity comparison will
work, but Identity hashing won't!

One real alternative is to default isEqual and hash to identity
operations and simply override them in subclasses that have a more
sophisticated notion.  This builds the identity a=a into the system,
but that doesn't really bother me.

On the other hand, as long as we don't use the class distinction as a
type distinction, I'm not worried.  We could even have xlint++ check
for this.  Since the dictinction would not be a type distinction, any
subclass of Object could redefine isEqual and hash to use identity
operations, and vice-versa.

AHA.  Here's a different hack that I like better for a variety of
reasons.  Define a macro IDENTITY_CLASS that expands to the
definitions of isEqual and hash for classes that distinguish based on
identity.  This makes it much more like an orthogonal property and
avoids making spurious type distinctions.