comp.lang.ada
 help / color / mirror / Atom feed
From: Lao Xiao Hai <laoxhai@ix.netcom.com>
Subject: Re: Redefined "=" = generic disaster?
Date: Mon, 30 Oct 2000 19:27:49 -0800
Date: 2000-10-31T03:33:15+00:00	[thread overview]
Message-ID: <39FE3C35.64CBB3C7@ix.netcom.com> (raw)
In-Reply-To: 8tkfme$v8a$1@nnrp1.deja.com



Robert Dewar wrote:

> In article <39FCEFAD.56BE85B1@ix.netcom.com>,
>   Lao Xiao Hai <laoxhai@ix.netcom.com> wrote:
> > Could not resist posting this package specification and body
> > in response to your challenge Robert.
>
> OK, you posted the code. My request was to post code that did
> something other than what you would expect from reading the
> code. I can't see that this is true, but then I am not
> telepathic, I cannot guess what peculiar expectations you
> might have.
>
> Please explain why this code does something different from
> what you expect?

As I recall, the discussion had something to do with unreliable
expectations with regard to overloading the equality operator.
It is true that someone reading my example would have no
particular expectation.   It is also true that your selection of
the word "peculiar" to describe the example is appropriate.

The point of the posting is that one can certainly overload the
equality operator in strange ways and those can be coded so
as to obfuscate any reasonable meaning.    It is a short step
from there to obfuscation of the intended meaning.   Sadly,
there are those among us (mostly in the C++ world, I suppose),
who seem to delight in obfuscated code.  In other cases, someone
does it thoughtlessly.   Just today, someone showed me a package
specification in which he had overloaded the equality operator for
a generic formal record parameter.   What he intended the equality
operator to do and what one might have reasonably expected were
far from the same.  I suggested the following, to coincide with his
intentions.

Instead of,

          function "=" (L, R : Item) return Boolean;

he needed,

         function Key_Is_Equal(L, R : Item) return Boolean;

With this operation, any user knows what to expect of the contract.
That is often not the case with overloading of the "=" by itself.

Richard Riehle




  reply	other threads:[~2000-10-31  3:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-21  6:59 Redefined "=" = generic disaster? Vincent Marciante
2000-10-21  0:00 ` Jeff Carter
2000-10-21  0:00   ` Vincent Marciante
2000-10-22  2:50     ` Jeff Carter
2000-10-22  0:00       ` Vincent Marciante
2000-10-21  0:00   ` Vincent Marciante
2000-10-28 11:12     ` Robert Dewar
2000-10-29  8:43       ` Vincent Marciante
2000-10-30  3:49       ` Lao Xiao Hai
2000-10-30 18:46         ` Robert Dewar
2000-10-31  3:27           ` Lao Xiao Hai [this message]
2000-10-31  6:54             ` Vincent Marciante
2000-10-31 19:51             ` Robert Dewar
2000-11-01 17:47               ` Mats Weber
2000-11-02  5:27                 ` Vincent Marciante
2000-11-02 16:52                   ` Mats Weber
2000-11-02 14:59                 ` Tucker Taft
2000-11-05  4:29                   ` Robert Dewar
2000-11-05  4:32                   ` Robert Dewar
2000-11-05  4:26                 ` Robert Dewar
replies disabled

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