comp.lang.ada
 help / color / mirror / Atom feed
* A good way to name instantiated children?
@ 2003-06-20 15:51 Dmitry A. Kazakov
  2003-06-20 21:06 ` Stephen Leake
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2003-06-20 15:51 UTC (permalink / raw)


Hi!

Let we have a chain of generic packages:

A.B.C.D...

Let the root A have a generic parameter, say,

   type Number is private;

Now, I want to instantiate all packages of the chain with Number => Float. 
The problem i,s how to name the children?

   package Float_A is new A (Float);

is fine, but the children cannot be named Float_A.B.C.D:

   with Float_A;
   with A.B;
   package Float_A.B is new Float_A.B; -- Error

(generic A.B contaminates the name space of Float_A). 

Float_A.Float_B.Float_C.Float_D looks awful.

Any ideas?

-- 
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: A good way to name instantiated children?
  2003-06-20 15:51 A good way to name instantiated children? Dmitry A. Kazakov
@ 2003-06-20 21:06 ` Stephen Leake
  2003-06-21  6:48   ` Simon Wright
  2003-06-21  7:12   ` Dmitry A. Kazakov
  0 siblings, 2 replies; 6+ messages in thread
From: Stephen Leake @ 2003-06-20 21:06 UTC (permalink / raw)


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

> Hi!
> 
> Let we have a chain of generic packages:
> 
> A.B.C.D...
> 
> Let the root A have a generic parameter, say,
> 
>    type Number is private;
> 
> Now, I want to instantiate all packages of the chain with Number => Float. 
> The problem i,s how to name the children?
> 
>    package Float_A is new A (Float);
> 
> is fine, but the children cannot be named Float_A.B.C.D:
> 
>    with Float_A;
>    with A.B;
>    package Float_A.B is new Float_A.B; -- Error
> 
> (generic A.B contaminates the name space of Float_A). 
> 
> Float_A.Float_B.Float_C.Float_D looks awful.
> 
> Any ideas?

I solve this by prefixing Gen_ to the generic package names:

generic
    type Number is private;
package Gen_A is ...

generic
package Gen_A.Gen_B is ...

Then the instantiations can be:

with Gen_A;
package Float_A is new Gen_A (Float);

with Gen_A.Gen_B;
package Float_A.B is new Float_A.Gen_B;

Yes, the Gen_A.Gen_B.Gen_C.Gen_D is a little ugly. But the
instantiation names are nice, which is more important. And it makes it
clear from the package name whether the package is generic or not,
which is also helpful.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: A good way to name instantiated children?
  2003-06-20 21:06 ` Stephen Leake
@ 2003-06-21  6:48   ` Simon Wright
  2003-06-21 19:43     ` Jeffrey Carter
  2003-06-21  7:12   ` Dmitry A. Kazakov
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Wright @ 2003-06-21  6:48 UTC (permalink / raw)


Stephen Leake <Stephe.Leake@nasa.gov> writes:

> I solve this by prefixing Gen_ to the generic package names:

I've used the suffix _G (still in >1 mind about it, though!)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: A good way to name instantiated children?
  2003-06-20 21:06 ` Stephen Leake
  2003-06-21  6:48   ` Simon Wright
@ 2003-06-21  7:12   ` Dmitry A. Kazakov
  1 sibling, 0 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2003-06-21  7:12 UTC (permalink / raw)


Stephen Leake wrote:

> I solve this by prefixing Gen_ to the generic package names:
> 
> generic
>     type Number is private;
> package Gen_A is ...
> 
> generic
> package Gen_A.Gen_B is ...
> 
> Then the instantiations can be:
> 
> with Gen_A;
> package Float_A is new Gen_A (Float);
> 
> with Gen_A.Gen_B;
> package Float_A.B is new Float_A.Gen_B;
> 
> Yes, the Gen_A.Gen_B.Gen_C.Gen_D is a little ugly. But the
> instantiation names are nice, which is more important. And it makes it
> clear from the package name whether the package is generic or not,
> which is also helpful.

Actually I am already calling the root generic packages Generic_Something. 
But I somehow missed the very fact that generic children are indeed 
generic! (:-)).

It is a good idea, thank you!

-- 
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: A good way to name instantiated children?
  2003-06-21  6:48   ` Simon Wright
@ 2003-06-21 19:43     ` Jeffrey Carter
  2003-06-23 13:39       ` Stephen Leake
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey Carter @ 2003-06-21 19:43 UTC (permalink / raw)


Simon Wright wrote:
> Stephen Leake <Stephe.Leake@nasa.gov> writes:
> 
>>I solve this by prefixing Gen_ to the generic package names:
> 
> I've used the suffix _G (still in >1 mind about it, though!)

The name of generic should relate to the thing it implements; the name 
of the instantiation, the application's need for such a thing. Coming up 
with good names for instantiations is an important part of making the 
S/W as self-documenting as possible.

As an example, the data structures in the PragmAda Reusable Components 
have generic procedures named Iterate. Instantiations should have names 
like Put_All, Sum, and so on, indicating what the application achieves 
by visiting each element in the structure. An instantiation named 
Iterate would not be properly descriptive.

If you are going to repeat "generic" in the name, a suffix is better 
than a prefix. Psychologically, the 1st few characters of identifiers 
are the most important in distinguishing them. If you have a lot of 
identifiers starting with the same thing, it makes your code harder to 
read. This applies to A_ and The_ on parameter names as well as to Gen_ 
on generics.

-- 
Jeff Carter
"If a sperm is wasted, God gets quite irate."
Monty Python's the Meaning of Life




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: A good way to name instantiated children?
  2003-06-21 19:43     ` Jeffrey Carter
@ 2003-06-23 13:39       ` Stephen Leake
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Leake @ 2003-06-23 13:39 UTC (permalink / raw)


Jeffrey Carter <spam@spam.com> writes:

> Simon Wright wrote:
> > Stephen Leake <Stephe.Leake@nasa.gov> writes:
> >
> >>I solve this by prefixing Gen_ to the generic package names:
> > I've used the suffix _G (still in >1 mind about it, though!)
> 
> <snip> 
> If you are going to repeat "generic" in the name, a suffix is better
> than a prefix. Psychologically, the 1st few characters of identifiers
> are the most important in distinguishing them. If you have a lot of
> identifiers starting with the same thing, it makes your code harder to
> read. This applies to A_ and The_ on parameter names as well as to
> Gen_ on generics.

Interesting point. I use a _Type suffix on types; I'm not sure why I
decided on a prefix for generics.

I have noticed that using tab completion on file names that start with
Gen is a pain; changing to a suffix would fix that.

Always good to get reviews from independent observers :).

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-06-23 13:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-20 15:51 A good way to name instantiated children? Dmitry A. Kazakov
2003-06-20 21:06 ` Stephen Leake
2003-06-21  6:48   ` Simon Wright
2003-06-21 19:43     ` Jeffrey Carter
2003-06-23 13:39       ` Stephen Leake
2003-06-21  7:12   ` Dmitry A. Kazakov

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