comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Generic package parameters not externally visible : what's the rational ?
Date: Sat, 31 Oct 2009 10:14:04 +0100
Date: 2009-10-31T10:14:06+01:00	[thread overview]
Message-ID: <1trjf9wxhbsqb$.14uxfibpc7k8x$.dlg@40tude.net> (raw)
In-Reply-To: d72dedd2-ca21-4c1c-acde-16b7e86a482f@b2g2000yqi.googlegroups.com

On Fri, 30 Oct 2009 19:06:56 -0700 (PDT), Hibou57 (Yannick Duch�ne) wrote:

> On 30 oct, 20:32, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> Do you use generic in other generics?
> 
> While I do not know if it is the kind of reply you were expected, here
> is mine : I use generics in other generics, when a generic has a
> formal type parameter which come from another generic package. If want
> want to assert the type T is provided (or derived from the one
> provided) by a package P, then both P and T must appear in the
> parameters. If P is generic (this can be legitimate), then you end up
> with a generic using another generic.
>
> Note : and in that case, this may be useful to make this package
> visible from the outside (exporting the content via renames and
> subtype, is not always done exhaustively)

Yes, I do it as well. This is the case when a formal parameter of a generic
is used in another generic.

Note that a generic child package can use formals of its parent. That is
the case why your proposal about visibility is so important in my eyes. It
is an *obvious* language bug.

The case is represented here:

generic
   type T is private;
package P is
end P;

generic
package P.Q is
   Y : T;
end P.Q;

with P.Q;
generic
   with package PQ is new P.Q (<>);
package R is
   X : PQ.T; -- Wring! You cannot see T, and there is no way to name it
end R;

In R you see Y of a "non-existent type".  This is obviously broken to me.

(Yes, I am extensively using the trick of subtype and renaming formal
parameters you wrote about earlier)

But as I said, generics are broken per their nature. With the time it gets
only worse. (:-()

> You may also understand you can have generics dealing with generics,
> when you use the Mixin pattern to add features in a well designed way,
> to that if you ever modify the Mixin package, then modifications
> applies to all the package created with this Minxin. The Mixin may be
> generic, and the package it receives as a parameter as well.

Yes I do it very often. But to give a word of warning, it is a road to
hell. In our current project the diagram of generic units is several pages
long, because of mixins. There is no other way because "high language
priests" have decided that multiple inheritance were bad for us, so the
language has crippled interface types instead of normal MI. The result is
just horrific. Mixin is a bad design pattern, but I wrote about it and
generics many times before.

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



  reply	other threads:[~2009-10-31  9:14 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-26  8:58 Generic package parameters not externally visible : what's the rational ? Hibou57 (Yannick Duchêne)
2009-10-26 11:05 ` Ludovic Brenta
2009-10-26 15:02   ` Robert A Duff
2009-10-27  1:06   ` Hibou57 (Yannick Duchêne)
2009-10-26 14:56 ` Robert A Duff
2009-10-27  3:03   ` Hibou57 (Yannick Duchêne)
2009-10-27 21:08   ` Randy Brukardt
2009-10-27 21:36     ` Jeffrey R. Carter
2009-10-27 22:03       ` Hibou57 (Yannick Duchêne)
2009-10-27 22:19         ` Jeffrey R. Carter
2009-10-28 19:07         ` Randy Brukardt
2009-10-29 12:18           ` Hibou57 (Yannick Duchêne)
2009-10-29 22:56             ` Randy Brukardt
2009-10-30  0:10               ` Hibou57 (Yannick Duchêne)
2009-10-27 22:04       ` Hibou57 (Yannick Duchêne)
2009-10-27 23:37       ` Robert A Duff
2009-10-27 23:41         ` Jeffrey R. Carter
2009-10-27 23:34     ` Robert A Duff
2009-10-28  2:19       ` Hibou57 (Yannick Duchêne)
2009-10-28 19:12         ` Randy Brukardt
2009-10-29  7:34           ` Stephen Leake
2009-10-29 12:21           ` Hibou57 (Yannick Duchêne)
2009-10-29 13:10             ` AdaMagica
2009-10-29 15:11               ` Georg Bauhaus
2009-10-29 19:28                 ` Jeffrey R. Carter
2009-10-29 20:27                   ` Georg Bauhaus
2009-10-30 10:30               ` Stephen Leake
2009-10-30 17:53             ` Ludovic Brenta
2009-10-31  2:10               ` Hibou57 (Yannick Duchêne)
2009-10-30  5:19           ` Hibou57 (Yannick Duchêne)
2009-10-28  9:09     ` Dmitry A. Kazakov
2009-10-28 19:19       ` Randy Brukardt
2009-10-29  8:36         ` Dmitry A. Kazakov
2009-10-29 23:03           ` Randy Brukardt
2009-10-30  8:51             ` Dmitry A. Kazakov
2009-10-30 10:25           ` Stephen Leake
2009-10-30 19:32             ` Dmitry A. Kazakov
2009-10-31  2:06               ` Hibou57 (Yannick Duchêne)
2009-10-31  9:14                 ` Dmitry A. Kazakov [this message]
2009-11-03  8:25                   ` Hibou57 (Yannick Duchêne)
2009-11-03  9:59                     ` Dmitry A. Kazakov
2009-11-05 10:38                       ` Hibou57 (Yannick Duchêne)
2009-11-05 11:00                         ` Dmitry A. Kazakov
2009-11-05 12:16                           ` Hibou57 (Yannick Duchêne)
2009-11-05 14:09                             ` Dmitry A. Kazakov
2009-11-06 12:19                               ` Hibou57 (Yannick Duchêne)
2009-11-06 13:27                                 ` Dmitry A. Kazakov
2009-10-31  2:08               ` Hibou57 (Yannick Duchêne)
2009-10-31 12:44               ` Stephen Leake
2009-11-01 11:37                 ` Dmitry A. Kazakov
replies disabled

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