comp.lang.ada
 help / color / mirror / Atom feed
* Ada 0y wish list: "with private"
@ 2001-02-12 13:41 Thierry Lelegard
  2001-02-13  0:10 ` Keith Thompson
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Thierry Lelegard @ 2001-02-12 13:41 UTC (permalink / raw)


Recently, several wishlist items for Ada 0y were posted in c.l.a.
Like many old Ada users, I have a couple of them. I would like to
propose one for discussion: a "with private" extension.

The idea is to specify in a context clause of a unit spec that an
external unit can be used only in the private part.

Example:

with A;
with private B;
package C is
   X : A.TA;
private
   Y : B.TB; -- legal only in private part
end C;

There are two advantages:

1) Readability. The user of package C is only interested in the public
   interface of C. Reading "with private B", the user knows that he may
   safely ignore what the strange unit B is all about.

2) Use of private packages in private parts. Example:

package Lib is ...

private package Lib.Internals is ....

with private Lib.Internals;
package Lib.Public is
    ....
private
    type TP is new Lib.Internals.TI ...
end Lib.Public;

The second point is, of course, more important than the first one. Some
of my recent code could have been much simpler with such a possibility.
In Ada 95, a private package cannot be referenced at all in the spec
of a public package, even in the private part, since the context clause
"with Lib.Internals" is simply refused.

Two points:
- The "with private" syntax is, of course, only a suggestion.
- Maybe there is some implementation flaw that I missed.

Any ideas or objections?
-Thierry
____________________________________________________________________________

Thierry Lelegard, "The Jazzing Troll", Email: thierry.lelegard@canal-plus.fr
CANAL+ Technologies, 34 place Raoul Dautry, 75516 Paris Cedex 15, France
Tel: +33 1 71 71 54 30   Fax: +33 1 71 71 52 08   Mobile: +33 6 03 00 65 75
____________________________________________________________________________





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

* Re: Ada 0y wish list: "with private"
  2001-02-12 13:41 Ada 0y wish list: "with private" Thierry Lelegard
@ 2001-02-13  0:10 ` Keith Thompson
  2001-02-13  0:13 ` Jeff Creem
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Keith Thompson @ 2001-02-13  0:10 UTC (permalink / raw)


"Thierry Lelegard" <thierry.lelegard@canal-plus.fr> writes:
> Recently, several wishlist items for Ada 0y were posted in c.l.a.
> Like many old Ada users, I have a couple of them. I would like to
> propose one for discussion: a "with private" extension.
> 
> The idea is to specify in a context clause of a unit spec that an
> external unit can be used only in the private part.
> 
> Example:
> 
> with A;
> with private B;
> package C is
>    X : A.TA;
> private
>    Y : B.TB; -- legal only in private part
> end C;

What about this syntax:

with A;
package C is
   X : A.TA;
private
   with B;
   Y : B.TB;
end C;

The advantage is that it puts the context clause within the private
part, which is what it applies to.

One possible drawback: Currently, the compiler sees all the context
clauses before the beginning of the package; with this syntax, it will
have to process the public declarations of C before seeing the "with
B;".  Some implementations would have more difficulty with this than
others; would it be an unreasonable burden for any of them?

(It also looks a bit odd to put a context clause into a sequence of
declarations.)

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
MAKE MONEY FAST!!  DON'T FEED IT!!



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

* Re: Ada 0y wish list: "with private"
  2001-02-12 13:41 Ada 0y wish list: "with private" Thierry Lelegard
  2001-02-13  0:10 ` Keith Thompson
@ 2001-02-13  0:13 ` Jeff Creem
  2001-02-13  6:37   ` Dale Stanbrough
  2001-02-13  8:48 ` Dr Adrian Wrigley
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Jeff Creem @ 2001-02-13  0:13 UTC (permalink / raw)



I am not entirely wild about this. It seems like a great way to break the
private abstraction and shoot
yourself. If C needs to need to know that much about B then it should be a
child of B.

Sure having something like this lets you be a little sloppier about the
interfaces you provide to users of
your package but without more of an example my gut tells me that you are
missing the reason things are
put in the private section.

"Thierry Lelegard" <thierry.lelegard@canal-plus.fr> wrote in message
news:968p1e$8m7$1@s1.read.news.oleane.net...
> Recently, several wishlist items for Ada 0y were posted in c.l.a.
> Like many old Ada users, I have a couple of them. I would like to
> propose one for discussion: a "with private" extension.
>
> The idea is to specify in a context clause of a unit spec that an
> external unit can be used only in the private part.
>
> Example:
>
> with A;
> with private B;
> package C is
>    X : A.TA;
> private
>    Y : B.TB; -- legal only in private part
> end C;
>
> There are two advantages:
>
> 1) Readability. The user of package C is only interested in the public
>    interface of C. Reading "with private B", the user knows that he may
>    safely ignore what the strange unit B is all about.
>
> 2) Use of private packages in private parts. Example:
>
> package Lib is ...
>
> private package Lib.Internals is ....
>
> with private Lib.Internals;
> package Lib.Public is
>     ....
> private
>     type TP is new Lib.Internals.TI ...
> end Lib.Public;
>
> The second point is, of course, more important than the first one. Some
> of my recent code could have been much simpler with such a possibility.
> In Ada 95, a private package cannot be referenced at all in the spec
> of a public package, even in the private part, since the context clause
> "with Lib.Internals" is simply refused.
>
> Two points:
> - The "with private" syntax is, of course, only a suggestion.
> - Maybe there is some implementation flaw that I missed.
>
> Any ideas or objections?
> -Thierry
>
____________________________________________________________________________
>
> Thierry Lelegard, "The Jazzing Troll", Email:
thierry.lelegard@canal-plus.fr
> CANAL+ Technologies, 34 place Raoul Dautry, 75516 Paris Cedex 15, France
> Tel: +33 1 71 71 54 30   Fax: +33 1 71 71 52 08   Mobile: +33 6 03 00 65
75
>
____________________________________________________________________________
>
>





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

* Re: Ada 0y wish list: "with private"
  2001-02-13  0:13 ` Jeff Creem
@ 2001-02-13  6:37   ` Dale Stanbrough
  2001-02-13 12:01     ` Jeff Creem
  0 siblings, 1 reply; 12+ messages in thread
From: Dale Stanbrough @ 2001-02-13  6:37 UTC (permalink / raw)


Jeff Creem  wrote:

> I am not entirely wild about this. It seems like a great way to break the
> private abstraction and shoot
> yourself. If C needs to need to know that much about B then it should be a
> child of B.
> 
> Sure having something like this lets you be a little sloppier about the
> interfaces you provide to users of
> your package but without more of an example my gut tells me that you are
> missing the reason things are
> put in the private section.


No, that's not the problem at all. It's not a matter of being
sloppy, it's about having the freedom to compose the abstractions
that you want to.

For example i have a type declared in a private
package, and would like this internal private type to be part of
the completion of a public type in a public package in the
package hierarchy. I never want the internal private type to be public, 
but Ada does not allow it.

Currently we have compilation privacy - what i want is implementation
privacy.

For example


   package A is
   end A;

   private package A.one is
      type P1 is private;
      procedure op1 (item : p1);
   private
      type P1 is something;
   end;



   with A.one;   -- can't do this.
   package A.two is
      type P2 is private;

      procedure op2 (Item : P2);
   private
      type P2 is new P1;
   end;


   with private A.one;   -- would like to do this...
   package A.two is
      type P2 is private;

      procedure op2 (Item : P2);
   private
      type P2 is new P1;
   end;

Certainly we are giving nothing away - the only operations available
outside the hierarchy would be those declared in package A.two. 

Certainly it shouldn't be necessary to implement "with private", as
a simple change to the rules (you can with the package, but if it
is private, you can only mention it in the private section).

What i want to do certainly does not compromise any of the data
hiding abilities of the language as it stands. It only affects how
things are compiled (it prevents clients from having to be recompiled
if an internal private component is recompiled).


dale



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

* Re: Ada 0y wish list: "with private"
  2001-02-12 13:41 Ada 0y wish list: "with private" Thierry Lelegard
  2001-02-13  0:10 ` Keith Thompson
  2001-02-13  0:13 ` Jeff Creem
@ 2001-02-13  8:48 ` Dr Adrian Wrigley
  2001-02-13  8:56 ` Michel Gauthier
  2001-02-13 16:31 ` Ehud Lamm
  4 siblings, 0 replies; 12+ messages in thread
From: Dr Adrian Wrigley @ 2001-02-13  8:48 UTC (permalink / raw)


Thierry Lelegard wrote:
> 
> Recently, several wishlist items for Ada 0y were posted in c.l.a.
> Like many old Ada users, I have a couple of them. I would like to
> propose one for discussion: a "with private" extension.

I'd like something a bit similar. "separate" for the private part.
This would allow the private part to be (for example) in a separate
file.  It could have its own context clause, thus obviating the
need for the "with private" extension.

I think the separation of the private part would make it easier
to separate the specification from the implementation properly.
For example, you usually need to edit the specification when
writing the implementation.  Project architects could forbid
this (keep the spec read-only) if the private was separate.

I seem to remember hearing this was discussed in the early
design of Ada, and abandoned because of the extra burden imposed.
It would obviate the "private   ... --  not specified by the language"
annotations in the ARM.

Perhaps the obvious syntax is "private is separate;" in the spec
where the full private part would have been.
--
Adrian Wrigley



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

* Re: Ada 0y wish list: "with private"
  2001-02-12 13:41 Ada 0y wish list: "with private" Thierry Lelegard
                   ` (2 preceding siblings ...)
  2001-02-13  8:48 ` Dr Adrian Wrigley
@ 2001-02-13  8:56 ` Michel Gauthier
  2001-02-13 16:31 ` Ehud Lamm
  4 siblings, 0 replies; 12+ messages in thread
From: Michel Gauthier @ 2001-02-13  8:56 UTC (permalink / raw)


In article <968p1e$8m7$1@s1.read.news.oleane.net>, "Thierry Lelegard"
<thierry.lelegard@canal-plus.fr> wrote:

>>  Recently, several wishlist items for Ada 0y were posted in c.l.a.
>>  Like many old Ada users, I have a couple of them. I would like to
>>  propose one for discussion: a "with private" extension.
>>  
>>  The idea is to specify in a context clause of a unit spec that an
>>  external unit can be used only in the private part.
>>  
>>  [...]

Everything that requires a comment should be evaluated for  
becoming a language construct.

This is an instance of this sensible rule of behaviour.

-----

"0Y" is better than "0X" since X has already been instantiated.
Thierry is right. 

Zero !  Why ?

----------          ----------          ----------          ---------- 
Michel Gauthier / Laboratoire d'informatique
83, rue d'Isle / F-87000 Limoges
telephone +33 555 43 69 73
fax +33 555 43 69 77
----------          ----------          ----------          ----------
Nous n'etions pas dans la langueur,
nous ne sombrons pas dans l'allegresse.
----------          ----------          ----------          ----------



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

* Re: Ada 0y wish list: "with private"
  2001-02-13  6:37   ` Dale Stanbrough
@ 2001-02-13 12:01     ` Jeff Creem
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Creem @ 2001-02-13 12:01 UTC (permalink / raw)


I think I see a little better what you are trying to accomplish. I am still
not sure I see
where this is really useful. I probably have addressed similar problems in
the past
somewhat differently by putting stuff from your private part in the public
area but then using
the Export set features of Rational Apex to limit what other packages can
with that special
package.

It does require a little more work on the part of the programmer but I think
it addresses more
cases. Perhaps (if it is not patented) we should look at the export set
feature of Apex for inclusion in
the language in some way.


"Dale Stanbrough" <dale@cs.rmit.edu.au> wrote in message
news:dale-1C6885.17292013022001@news-server...
> Jeff Creem  wrote:
>
> > I am not entirely wild about this. It seems like a great way to break
the
> > private abstraction and shoot
> > yourself. If C needs to need to know that much about B then it should be
a
> > child of B.
> >
> > Sure having something like this lets you be a little sloppier about the
> > interfaces you provide to users of
> > your package but without more of an example my gut tells me that you are
> > missing the reason things are
> > put in the private section.
>
>
> No, that's not the problem at all. It's not a matter of being
> sloppy, it's about having the freedom to compose the abstractions
> that you want to.
>
> For example i have a type declared in a private
> package, and would like this internal private type to be part of
> the completion of a public type in a public package in the
> package hierarchy. I never want the internal private type to be public,
> but Ada does not allow it.
>
> Currently we have compilation privacy - what i want is implementation
> privacy.
>
> For example
>
>
>    package A is
>    end A;
>
>    private package A.one is
>       type P1 is private;
>       procedure op1 (item : p1);
>    private
>       type P1 is something;
>    end;
>
>
>
>    with A.one;   -- can't do this.
>    package A.two is
>       type P2 is private;
>
>       procedure op2 (Item : P2);
>    private
>       type P2 is new P1;
>    end;
>
>
>    with private A.one;   -- would like to do this...
>    package A.two is
>       type P2 is private;
>
>       procedure op2 (Item : P2);
>    private
>       type P2 is new P1;
>    end;
>
> Certainly we are giving nothing away - the only operations available
> outside the hierarchy would be those declared in package A.two.
>
> Certainly it shouldn't be necessary to implement "with private", as
> a simple change to the rules (you can with the package, but if it
> is private, you can only mention it in the private section).
>
> What i want to do certainly does not compromise any of the data
> hiding abilities of the language as it stands. It only affects how
> things are compiled (it prevents clients from having to be recompiled
> if an internal private component is recompiled).
>
>
> dale





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

* Re: Ada 0y wish list: "with private"
  2001-02-12 13:41 Ada 0y wish list: "with private" Thierry Lelegard
                   ` (3 preceding siblings ...)
  2001-02-13  8:56 ` Michel Gauthier
@ 2001-02-13 16:31 ` Ehud Lamm
  4 siblings, 0 replies; 12+ messages in thread
From: Ehud Lamm @ 2001-02-13 16:31 UTC (permalink / raw)


> Example:
>
> with A;
> with private B;
> package C is
>    X : A.TA;
> private
>    Y : B.TB; -- legal only in private part
> end C;
>

I like this idea. I think it is good the the with clause is not inside the
private part, and I like the way this enhaces readability and good design.

Ehud





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

* RE: Ada 0y wish list: "with private"
@ 2001-02-15  1:04 Beard, Frank
  2001-02-15  4:18 ` Jeffrey Carter
  0 siblings, 1 reply; 12+ messages in thread
From: Beard, Frank @ 2001-02-15  1:04 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

I would love to see this added to the language.  What I have
long wished for is to be able to do the following:

   package A is

      type B is private;

   private

      type B;  -- If the completion is not here,
               -- then it's deferred to the body

   end A;

   package body A is

      type B is ...;

   end A;

This would allow the separation of the spec and body without
the bother of using an access type, and the associated dangling
memory and garbage collection issues.

While Dr. Wrigley indicated that it could be in a separate
file, I'm not sure if what I described above is what he meant
or if he's talking about a separate off of the spec.  But, I
would have not problem with it being required to be in the
package body.

Frank


-----Original Message-----
From: Dr Adrian Wrigley [mailto:amtw@linuxchip.demon.co.uk]

I'd like something a bit similar. "separate" for the private part.
This would allow the private part to be (for example) in a separate
file.  It could have its own context clause, thus obviating the
need for the "with private" extension.

I think the separation of the private part would make it easier
to separate the specification from the implementation properly.
For example, you usually need to edit the specification when
writing the implementation.  Project architects could forbid
this (keep the spec read-only) if the private was separate.





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

* Re: Ada 0y wish list: "with private"
  2001-02-15  1:04 Beard, Frank
@ 2001-02-15  4:18 ` Jeffrey Carter
  0 siblings, 0 replies; 12+ messages in thread
From: Jeffrey Carter @ 2001-02-15  4:18 UTC (permalink / raw)


"Beard, Frank" wrote:
> 
> What I have
> long wished for is to be able to do the following:
> 
>    package A is
> 
>       type B is private;
> 
>    private
> 
>       type B;  -- If the completion is not here,
>                -- then it's deferred to the body
> 
>    end A;
> 
>    package body A is
> 
>       type B is ...;
> 
>    end A;
> 
> This would allow the separation of the spec and body without
> the bother of using an access type, and the associated dangling
> memory and garbage collection issues.

Yes, or even

package A is
   type B is private;
   -- operations on B
end A;

package body A is
   type B is ...;
end A;

I submitted this as a 9X revision request, but it was rejected on the
grounds that one can achieve the same effect with an access type:

package A is
   type B is private;
   -- operations on B
private
   type X;
   type Y is access all X;
   type B is new Finalization.Controlled with record
      Z : Y;
   end record;
   -- procedures Initialize, Adjust, and Finalize
end A;

However, this is qualitatively different. I want to be able to use B as
B, and not have to get into all the details of it actually being an
access type. Let the compiler deal with all that. I suppose this would
involve a certain amount of work for compiler developers for what such
developers see as a small gain.

-- 
Jeff Carter
"Sons of a silly person."
Monty Python & the Holy Grail



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

* RE: Ada 0y wish list: "with private"
@ 2001-02-15  4:53 Christoph Grein
  0 siblings, 0 replies; 12+ messages in thread
From: Christoph Grein @ 2001-02-15  4:53 UTC (permalink / raw)
  To: comp.lang.ada

   package A is

      type B is private;

   private

   end A;

   package body A is

      type B is ...;

   end A;

There are severe code generation problem with this proposal. When the spec of A 
is compiled, the compiler has to know how big objects of type B are. So the full 
declaration has to go into the spec.

   package A is

      type B is private;

   private

      type X;
      type B is access X;

   end A;

   package body A is

      type X is ...;

   end A;

With this solution, it's definitely clear how big B is, irrespective of the size 
of X;





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

* RE: Ada 0y wish list: "with private"
@ 2001-02-15 19:16 Beard, Frank
  0 siblings, 0 replies; 12+ messages in thread
From: Beard, Frank @ 2001-02-15 19:16 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

I disagree.  If the compiler treated the deferred type
as a "by reference" type then there wouldn't be a problem.
It would be similar to an access type without the requirement
of allocation/deallocation, null checks, etc.

When a variable of type B is declared, the compiler will
always pass it by reference (by address), which is the
equivalent of passing an access type.

Frank

-----Original Message-----
From: Christoph Grein [mailto:christoph.grein@eurocopter.de]
Sent: Wednesday, February 14, 2001 11:54 PM
To: comp.lang.ada@ada.eu.org
Subject: RE: Ada 0y wish list: "with private"


   package A is

      type B is private;

   private

   end A;

   package body A is

      type B is ...;

   end A;

There are severe code generation problem with this proposal. When the spec
of A 
is compiled, the compiler has to know how big objects of type B are. So the
full 
declaration has to go into the spec.





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

end of thread, other threads:[~2001-02-15 19:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-12 13:41 Ada 0y wish list: "with private" Thierry Lelegard
2001-02-13  0:10 ` Keith Thompson
2001-02-13  0:13 ` Jeff Creem
2001-02-13  6:37   ` Dale Stanbrough
2001-02-13 12:01     ` Jeff Creem
2001-02-13  8:48 ` Dr Adrian Wrigley
2001-02-13  8:56 ` Michel Gauthier
2001-02-13 16:31 ` Ehud Lamm
  -- strict thread matches above, loose matches on Subject: below --
2001-02-15  1:04 Beard, Frank
2001-02-15  4:18 ` Jeffrey Carter
2001-02-15  4:53 Christoph Grein
2001-02-15 19:16 Beard, Frank

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