equals()?

3 views
Skip to first unread message

Raoul Duke

unread,
Nov 22, 2021, 11:27:04 AM11/22/21
to pi...@googlegroups.com
in the presence of subtyping of various ilk, what are the best ways to implement equality checks (of various ilk, too)? both in terms of language design & core sdk but also in terms of end users having to implement custom. 

Mike Austin

unread,
Nov 22, 2021, 4:20:25 PM11/22/21
to PiLuD

Raoul Duke

unread,
Nov 22, 2021, 4:27:21 PM11/22/21
to pi...@googlegroups.com
overall i think there's no actual answer other than everything is
custom all the time. there might be some standard common things but
even those quickly fall apart e.g. if you have a class that was never
subclassed then when somebody else does the subclassing often equals
can go to hell. it all seems very very very complex/complicated, and
i've never seen e.g. a full document / book / tome on how to deal with
all the possibilities, let alone what that should tell us all about
language design. (and unit tests.)
> --
> You received this message because you are subscribed to the Google Groups "PiLuD" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pilud+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pilud/90dd5a14-d853-4767-8586-cbc58ac8e792n%40googlegroups.com.

Mike Austin

unread,
Nov 23, 2021, 5:01:11 PM11/23/21
to PiLuD
I get what you're saying now. Using traits, you can require the user provide a '==', else it doesn't work. Overriding a class with an existing '==', yeah, is broken, unless you use abstract classes. Inheriting from concrete classes will always have issues. Fragile base class, multiple inheritance, etc. Traits / typeclasses seem to be the best solution. Share the behavior, not the concrete class.
Reply all
Reply to author
Forward
0 new messages