comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: advice on package design
Date: 12 Mar 2005 14:57:17 -0500
Date: 2005-03-12T14:57:17-05:00	[thread overview]
Message-ID: <wcc64zw63j6.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1gbk0qx2sgzpg$.sltzfssofla8$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> 3. You can rename parts of contents of Baz in Foo:
> 
> package Foo is
>    type Word is ...
>    package Baz is new Bar (Word, ...);
> 
>    subtype Linked_List is Baz.Linked_List; -- "renaming" of a type
>    procedure Insert (...) renames Baz.Insert; -- renaming of a procedure
>    ...
> end Foo;

One variation on that is to declare a derived type:

    type Linked_List is new Baz.Linked_List;

This causes all of the primitive subprograms of Baz.Linked_List to be
inherited -- implicitly declared in Foo.  But for anything that's not a
primitive subprograms, you have to write some wrapper code by hand.

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.

It really is a flaw in Ada that you can't easily re-export stuff.
The renaming solution is bad because it is verbose, and therefore
error prone.  I still remember a bug I fixed many years ago:

    function "and"(...) return ... renames Something."and";
    function "or"(...) return ... renames Something."or";
    function "xor"(...) return ... renames Something."or";

The problem is that renaming is *not* usually used to rename things --
it is used to import them (with the *same* name) into a different
scope.  Given that mindset, it took me a *long* time to notice the bug
in the above.  The symptom was that xor was behaving strangely in some
faraway place.

That was Ada 83.  In Ada 95, "use type" would have prevented the
problem.

- Bob



  parent reply	other threads:[~2005-03-12 19:57 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 [this message]
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
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