comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Top 10 Worst C# Features
Date: Thu, 15 Oct 2015 05:24:12 -0700 (PDT)
Date: 2015-10-15T05:24:12-07:00	[thread overview]
Message-ID: <8f252b53-4d99-4d4c-893c-66ec29ec38d6@googlegroups.com> (raw)
In-Reply-To: <87mvvla5ma.fsf@bsb.me.uk>


> Do you mean that there are reasons to permit !(a == b) and a != b to
> have different values in some cases?

Why not? We are already talking about the language where a+b is not necessarily equal to b+a (hint: strings). ;-)

There is also an interesting area for objects that might be neither "equal" nor "different" (that is, where both operators might return false at the same time).
As an illustration, Apples and Oranges are neither equal nor different, even though they are all Fruits and might be modeled in a flat type system.

Of course, diverting from the usual laws is asking for trouble, but as I have already said - some programmers might be willing to get some added flexibility at the expense of higher verification effort. Definitely, one should not automatically assume that all C++ programmers are morons.

> I don't see why
> 
>   bool operator!=(const T &other) const noexcept
>   {
>     if (this.hash != other.hash)
>       return true;
>     return !this.long_slow_equality_test(other);
>   }
> 
> is any more or less efficient than
> 
>   bool operator==(const T &other) const noexcept
>   {
>     if (this.hash != other.hash)
>       return false;
>     return this.long_slow_equality_test(other);
>   }
> 
> but I may have missed the point you are trying to make.

No, but you have missed the point that I tried to address. Your example is OK with regard to performance, but for some reason you have still used *distinct* implementations of these operators, instead of calling one from another. And interestingly, your WCET is even worse than in my example, as it might need to execute two comparisons (fast and slow) instead of just the one which is asked for.

Of course, I don't claim that these are typical usage scenarios. Typically, these operators indeed should be based on common logic.

-- 
Maciej Sobczak * http://www.inspirel.com


  parent reply	other threads:[~2015-10-15 12:24 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02 10:59 Top 10 Worst C# Features Stefan.Lucks
2015-09-02 17:37 ` Álex R. Mosteo
2015-09-02 19:39 ` Randy Brukardt
2015-09-03  8:14   ` Georg Bauhaus
2015-09-03  9:26     ` Dmitry A. Kazakov
2015-09-03 11:39       ` G.B.
2015-09-03 12:00         ` G.B.
2015-09-03 13:59           ` Dmitry A. Kazakov
2015-09-03 19:12           ` Randy Brukardt
2015-09-04  7:33             ` Georg Bauhaus
2015-09-04 21:34               ` Randy Brukardt
2015-09-05  6:31                 ` Dmitry A. Kazakov
2015-09-05  6:44                 ` Georg Bauhaus
2015-09-05  7:07                   ` Dmitry A. Kazakov
2015-09-05  6:45                 ` Niklas Holsti
2015-09-05  7:21                   ` Dmitry A. Kazakov
2015-09-05 12:07                   ` Peter Chapin
2015-09-06 10:45                   ` Georg Bauhaus
2015-10-13 19:57                   ` Eryndlia Mavourneen
2015-09-05  7:16                 ` Shark8
2015-09-03 13:47         ` Dmitry A. Kazakov
2015-09-03  8:51 ` gautier_niouzes
2015-10-01 14:03 ` Paul Colin de Gloucester
2015-10-14  8:00   ` Maciej Sobczak
2015-10-14 14:26     ` Ben Bacarisse
2015-10-14 16:50       ` Paul Rubin
2015-10-14 18:17         ` Stefan.Lucks
2015-10-14 19:54           ` Ben Bacarisse
2015-10-15 12:24       ` Maciej Sobczak [this message]
2015-10-15 13:59         ` Ben Bacarisse
2015-11-06 14:50     ` Nicholas Collin Paul de Gloucester
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox