A fresh look at comparisons

Bruce Adams tortoise_74 at yeah.who.co.uk
Tue Apr 15 16:57:00 PDT 2008


On Tue, 15 Apr 2008 10:07:31 +0100, Janice Caron <caron800 at googlemail.com>  
wrote:

> On 15/04/2008, Bruce Adams <tortoise_74 at yeah.who.co.uk> wrote:
>>  I don't think even this is safe. The normal definition of inheritance  
>> is
>
> Well, that's kindof the point. is(==) wouldn't /use/ inheritance. It
> wouldn't be inheritable. It's just like constructors aren't
> inheritable.
>
> The whole point is the recognition that inheritance is not the right
> mechanism when it comes to comparisons, and hence the quest for a
> different mechanism that /is/ appropriate.
>
You misunderstand me. I believe that the operation should be undefined
rather than providing a stub that returns false. As the presence of even a  
stub
function here is misleading.

class A;
class B: A;
class C: A;

B == C   // should not compile - unless user defined

>
>>  Yes. The semantics are there. We just need to find a syntax that fits
>> better with D.
>>  This doesn't quite sit right when everything else is an Op-something.
>
> It wouldn't be a function in the conventional sense. Choosing a syntax
> that makes it look /not/ like a function is entirely deliberate. It's
> just like constructors don't look like functions; destructors don't
> look like functions; class invariants don't look like functions; unit
> tests don't look like functions.
>
> opAdd() is a function, subject to all the normal rules of functions,
> including inheritance, overloading, overriding, etc. They're different
> beasts, so they need to look different, syntactically.
>
> (Also, I chose "is" so as to avoid introducing a new keyword).

I disagree here. Constructors and destructors are special kinds of function
but they are still functions. The difference is that some special semantics
are apply in addition to normal functional behaviour.
Operators are syntactic sugar to map symbols to functions.
The function is a fundermental unit and one which everyone understands.
Attempting to mask or hide that is counter intuitive.

Regards,

Bruce.



More information about the Digitalmars-d mailing list