From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: Top 10 Worst C# Features
Date: Thu, 15 Oct 2015 14:59:51 +0100
Date: 2015-10-15T14:59:51+01:00 [thread overview]
Message-ID: <87si5c8c6g.fsf@bsb.me.uk> (raw)
In-Reply-To: 8f252b53-4d99-4d4c-893c-66ec29ec38d6@googlegroups.com
Maciej Sobczak <see.my.homepage@gmail.com> writes:
>> 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). ;-)
I asked because I wanted to know the context for the remark that
prompted my reply. That remark was
In this case [when there is a hash or signature], our operator!= can
be much faster than operator== and we are willing to benefit from the
optimization opportunity here.
<snip>
>> 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.
No, I've just given an example of both because I disputed this remark:
In this case [when there is a hash or signature], our operator!= can
be much faster than operator== and we are willing to benefit from the
optimization opportunity here.
There is no reason at all to use both, but the easiest way to explain
why I find the claim hard to accept is to show both. In practice,
either one will do with the other implemented as the negation of the one
chosen.
You claimed that the case you gave (where the objects have a hash or
signature that allows for rapid non-equality testing) was an example
where separate implementations of != and == would be advantageous, but
what you described is not enough for the conclusion to hold. That's
why I asked about !(a != b) == (a == b).
<snip>
--
Ben.
next prev parent reply other threads:[~2015-10-15 13:59 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
2015-10-15 13:59 ` Ben Bacarisse [this message]
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