comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: advice on package design
Date: Thu, 17 Mar 2005 11:22:11 +0100
Date: 2005-03-17T11:18:39+01:00	[thread overview]
Message-ID: <18e9a92kz25wu$.8b965bel5vef$.dlg@40tude.net> (raw)
In-Reply-To: wcck6o7s4q4.fsf@shell01.TheWorld.com

On 16 Mar 2005 15:41:55 -0500, Robert A Duff wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> On 12 Mar 2005 16:59:26 -0500, Robert A Duff wrote:
>> 
>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>> 
>> That makes sense, but it might be difficult for the programmer to resolve
>> the problem. Somewhere in 20th child package of B he calls Foo and, oops,
>> it is ambiguous. I think it is better to keep all scopes clean from the
>> beginning.
> 
> I see your point, but I think that can be dealt with by having good
> error messages.  In any language that allows overloading, there are
> going to potential ambiguities, and when they happen, I expect more from
> the compiler than just "error: I'm confused".
> 
> In Ada, if you have:
> 
> procedure Foo(X: Integer);
> procedure Foo(Y: Integer);
> 
> in the same package, it's illegal.  But if they're in two different
> packages, both use-visible, then it's legal, and you can call them
> using named notation: Foo(X => 1) vs. Foo(Y => 1).  That seems odd
> to me.  Should that use clause be illegal?

Yes, at least "transitive use" should be. Otherwise, overloading of two
Foo's should be allowed (which would be bad).

Good error messages might be OK from the perspective of a package user. But
from the package designer's one it is not enough, when he wants to make his
packages "use"-friendly, especially "transitive use"-friendly.

> ...  And don't make the
> overload-resolution rules too "smart", so they make many things
> ambiguous (and therefore illegal).

I definitely agree with this.

>> Alas, but preference rules cannot be avoided. Overriding is just that
>> preference.
> 
> I don't see why.  Overriding is different -- the old thing goes away.
> It's explicit, so it's OK.

Presently it is not explicit. Syntactically overriding is undistinguishable
from declaring a new operation. This is IMO bad. It should be sort of:

procedure Override (X : Object) is ????;
   -- Overriding intended, fails if base types have no primitive Override
procedure Override (X : Object);
   -- Overloading intended, fails if it hides any other Override

>  If we had this language:
> 
> declare
>    I : Integer;
> begin
>    hide I;     <<<<<<<<<<<<<<<<<<<<<<<<
>    for I in A'Range loop
>       A (I) := 0;
>    end loop;
> 
> then the hiding would be OK, IMHO.

I agree with the idea, but I think that hiding should appear in a
declarative part. Less probably it should also qualify the thing being
hidden (like renames does):

declare
   I : Integer;
begin
   declare
      I : Integer is null; -- Know me, if you want to get rid of me!
   begin
      for I in A'Range loop
         A (I) := 0;
      end loop;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-03-17 10:22 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-07 16:23 advice on package design spambox
2005-03-07 21:08 ` Dmitry A. Kazakov
2005-03-08 12:48   ` spambox
2005-03-08 17:18     ` Dmitry A. Kazakov
2005-03-12 19:57   ` Robert A Duff
2005-03-12 20:45     ` Dmitry A. Kazakov
2005-03-12 21:59       ` Robert A Duff
2005-03-13  9:23         ` Dmitry A. Kazakov
2005-03-16 20:41           ` Robert A Duff
2005-03-17 10:22             ` Dmitry A. Kazakov [this message]
2005-03-17 14:04               ` Robert A Duff
2005-03-17 15:59                 ` Dmitry A. Kazakov
2005-03-17 19:10                   ` Robert A Duff
2005-03-17 19:47                     ` Martin Dowie
2005-03-17 20:55                       ` Robert A Duff
2005-03-17 21:14                         ` Marius Amado Alves
2005-03-18  9:31                           ` Martin Dowie
2005-03-18  9:38                         ` Martin Dowie
2005-03-21 16:19                           ` Robert A Duff
2005-03-17 20:48                     ` Dmitry A. Kazakov
2005-03-17 21:26                       ` Robert A Duff
2005-03-18  3:06                         ` Jared
2005-03-18 10:00                         ` Dmitry A. Kazakov
2005-03-21 16:17                           ` Robert A Duff
2005-03-21 18:16                             ` Dmitry A. Kazakov
2005-03-21 20:35                               ` Robert A Duff
2005-03-22 10:55                                 ` Dmitry A. Kazakov
2005-03-17 23:23                 ` Randy Brukardt
replies disabled

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