All right, all right! Interim decision regarding qualified Object methods

Jonathan M Davis jmdavisProg at gmx.com
Thu Jul 12 19:19:35 PDT 2012


On Thursday, July 12, 2012 22:08:01 Steven Schveighoffer wrote:
> On Thu, 12 Jul 2012 18:38:06 -0400, Andrei Alexandrescu
> 
> <SeeWebsiteForEmail at erdani.org> wrote:
> > On 7/12/12 4:50 PM, Steven Schveighoffer wrote:
> >> My personal opinion is we should simply eliminate the four methods (or
> >> at least the three required for AAs), fix AAs, and deal with the
> >> fallout. I can't really remember the last time I simply used
> >> obj1.opEquals(obj2) to do comparisons instead of obj1 == obj2 (which
> >> should do the right thing if obj1.opEquals(obj2) is valid). The code
> >> that relies on this is probably very rare. I certainly would *love* to
> >> rewrite all my opCmp and opEquals functions to accept the minimal base
> >> class instead of doing the dual dispatch dance with Object parameters.
> > 
> > I agree not a lot of people use obj1.opEquals(obj2) instead of obj1 ==
> > obj2, but I assume quite a few override opEquals and rely on it being
> > called.
> 
> (fixed above for you)
> 
> Yes, and why would that not work? If opEquals is defined as:
> 
> bool opEquals(Object o)
> 
> Won't this still be called by the compiler, even if Object does not define
> it? (assuming the extraneous override keyword is removed)

That raises an interesting point. With these changes, what should opEquals' 
signature be for classes? Right now, it's always

bool opEquals(Object obj);

Would it still have to be that? It wouldn't really make sense for it be, since 
you couldn't use == on Object. Would it then use the most basic class which 
uses (i.e. the least derived class) which implements opEquals? Or would each 
derived class implement it with their type? Doing that causes overload issues, 
because then you have to alias every base class' overload to be able to use == 
against every base class' type. Is the solution to then to template opEquals 
and make it non-virtual? I don't know. D's overload rules could make this a 
bit interesting. We need to figure out exactly what opEquals' and opCmp's 
signatures are going to need to look like.

- Jonathan M Davis


More information about the Digitalmars-d mailing list