comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: advice on package design
Date: Sun, 13 Mar 2005 10:23:02 +0100
Date: 2005-03-13T10:22:51+01:00	[thread overview]
Message-ID: <88zllqj1min5$.fqqxis9i327d$.dlg@40tude.net> (raw)
In-Reply-To: wccsm30ttj5.fsf@shell01.TheWorld.com

On 12 Mar 2005 16:59:26 -0500, Robert A Duff wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> On 12 Mar 2005 14:57:17 -0500, Robert A Duff wrote:
>> 
>>> If I were [re]designing Ada, I would make 'use' transitive. That is,
>>> if Foo says "use Linked_List" that would make the contents of
>>> Linked_List directly visible in Foo, and anything that says "use Foo;"
>>> would have direct visibility on everything directly visible in Foo --
>>> not just the things *declared* in Foo.  Or something like that.
>> 
>> Yes, I really miss it. What about:
>> 
>>    use all <package-name>;
>> 
>> or
>> 
>>   use package <package-name>;
>> 
>> with the effect importing the specification of the package? Also,
>> differently to use, it should prevent hiding. So:
>> 
>> package A is
>>    Foo (X : Integer);
>> end A;
>> 
>> with A;
>> package B is
>>    use all A;
>>    Foo (X : out Integer); -- Illegal, can't hide A.Foo
>> end B;
> 
> Well, I happen to think that *all* hiding is evil.
> I would make the above legal, but all calls to Foo would be ambiguous,
> and therefore illegal.

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.

> Ichbiah defined "Beaujolais Effect" to mean that if you add a subprogram
> to a use-d package, and that causes a legal program to change it's
> meaning (to another legal program) you have a Beaujolais Effect.
> And Beaujolais Effects are bad.  Ada 83 had some Beaujolais Effects,
> but they were pretty obscure, and we eliminated them in Ada 95.
> 
> But I think he should have extended that definition to include all
> visibility, not just use-visibility.  So a local X should not hide a
> use-visible X, but be ambiguous with it.

Yes. Even in the cases like:

declare
   I : Integer;
begin
   for I in A'Range loop
      A (I) := 0;
   end loop;

However I'd like to get error message one line above than you.

> And similar rules for record
> (extension) components.

I think that this case is not so simple. IMO record components should be
treated as primitive operations (getter/setter pair). As such they could be
overridden upon extension. At the same time some of the components might be
declared as a kind of "class-wide". For these the rules preventing hiding
should apply.

> In Pascal, a 'with' statement opens up the visibility of the record
> components, and if 'with R' is nested within some place where X is
> declared, then record component X hides that X.  That's bad, and Ichbiah
> wisely designed 'use' clauses to not do that bad thing.  The trick is to
> avoid "preference rules", where one decl takes precedence over another.
> But hiding is exactly a preference rule (preferring the inner one over
> an outer one, or preferring an outer one over a use-visible one).

Alas, but preference rules cannot be avoided. Overriding is just that
preference.

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



  reply	other threads:[~2005-03-13  9:23 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 [this message]
2005-03-16 20:41           ` Robert A Duff
2005-03-17 10:22             ` Dmitry A. Kazakov
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