comp.lang.ada
 help / color / mirror / Atom feed
From: Mats Weber <Mats.Weber@elca-matrix.ch>
Subject: Re: Help - Constructors - ASAP.
Date: 1998/08/03
Date: 1998-08-03T00:00:00+00:00	[thread overview]
Message-ID: <35C5C534.D773CAA2@elca-matrix.ch> (raw)
In-Reply-To: m3vhodvevl.fsf@mheaney.ni.net

Matthew Heaney wrote:

> You can do this with non-tagged types too.  One common mistake I see
> programmers make is to do this:
> 
> package P is
> 
>    package Bounded_Strings_20 is
>      new Ada.Strings.Bounded.Generic_Bounded_Length (20);
> ...
> end P;
> 
> Now every client in the universe has to refer to the string type as
> P.Bounded_Strings_20.Bounded_String.  Why should a client care?
> 
> Use the transitivity of visibility technique to bring the string type
> directly in the scope of P:
> 
> package P is
> 
>    package Bounded_Strings_20 is
>      new Ada.Strings.Bounded.Generic_Bounded_Length (20);
> 
>    type Bounded_String is
>      new Bounded_Strings_20.Bounded_String;
> ...
> end P;
> 
> Now a client can just refer to P.Bounded_String.

This works as long as the package that implements the type exports only one
type and only primitive operations of that one type, but that is far from the
most common case, at least in my code. Take for instance Sequential_IO:

package P is

   package Implementation is new Sequential_IO(Whatever);

   type File_Type is new Implementation.File_Type;
   type File_Mode is ???; -- no clean way of doing this

end P;

Another problem, which I think is even worse, is when some operations of a
type are generics (e.g. iterators), then these will not be derived and you
will have to get them from the package that declares them.

Not to mention the fact that the rules on type derivation, primitive
operations, etc. are one of the obscure areas of the Ada language. Not to me,
I know how they work, but I have had to teach quite a few people to overtake
code that uses some (really not much) type derivation, and nobody seems to
find it natural. E.g. when you see

   X : P.T;

begin
   P.Op(X);

you expect to find a declaration for Op in P, right ?




  reply	other threads:[~1998-08-03  0:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-07-23  0:00 Help - Constructors - ASAP Maxim Senin
1998-07-26  0:00 ` Matthew Heaney
1998-07-27  0:00   ` dennison
1998-07-30  0:00     ` Robert I. Eachus
1998-07-30  0:00       ` tedennison
1998-07-31  0:00         ` Matthew Heaney
1998-07-31  0:00         ` Mats Weber
1998-07-31  0:00           ` Robert I. Eachus
1998-08-01  0:00             ` Matthew Heaney
1998-07-31  0:00           ` dennison
1998-08-01  0:00             ` Matthew Heaney
1998-08-01  0:00             ` Robert Dewar
1998-08-01  0:00               ` Matthew Heaney
1998-08-03  0:00             ` Mats Weber
1998-08-01  0:00       ` Robert Dewar
1998-08-01  0:00         ` Matthew Heaney
1998-08-03  0:00           ` Mats Weber [this message]
1998-08-03  0:00             ` Matthew Heaney
1998-08-03  0:00               ` Mats Weber
1998-08-04  0:00                 ` Matthew Heaney
1998-08-04  0:00                   ` Mats Weber
1998-08-05  0:00                     ` Matthew Heaney
1998-08-10  0:00           ` Robert I. Eachus
1998-08-03  0:00         ` tedennison
  -- strict thread matches above, loose matches on Subject: below --
1998-07-15  0:00 Maxim Senin
1998-07-16  0:00 ` Stephen Leake
replies disabled

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