comp.lang.ada
 help / color / mirror / Atom feed
* Ada 83 - Rep clause inside private area question
@ 1997-04-18  0:00 Angelo A. Keene
  1997-04-20  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 3+ messages in thread
From: Angelo A. Keene @ 1997-04-18  0:00 UTC (permalink / raw)




If I have two Ada83 packages, defined as follows -- what are the 
differences between the two, if any?  Would a user of this package
not have access to the 'SIZE function now?

package Test_Types_One is

   Type My_Enum is (
      Alpha,
      Beta,
      Gamma
   );

   for My_Enum use (
      Alpha => 5,
      Beta  => 7,
      Gamma => 10,
   )

   for My_Enum'SIZE use 16;

end Test_Types_One;

package Test_Types_Two is

   Type My_Enum is (
      Alpha,
      Beta,
      Gamma
   );

private

   for My_Enum use (
      Alpha => 5,
      Beta  => 7,
      Gamma => 10,
   )

   for My_Enum'SIZE use 16;

end Test_Types_Two;

While building a short test package, I accidentally ended up with a
package in the second form, which compiles successfully -- but after
looking at it, I started thinking about the implications of what I
wrote -- looking at my available references, I can't determine
if the second form would have any useful meaning or not.

TIA for any insights!

Angelo A. Keene
akeene@hercii.mar.lmco.com




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

* Re: Ada 83 - Rep clause inside private area question
  1997-04-18  0:00 Ada 83 - Rep clause inside private area question Angelo A. Keene
@ 1997-04-20  0:00 ` Matthew Heaney
  1997-04-20  0:00   ` Robert Dewar
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Heaney @ 1997-04-20  0:00 UTC (permalink / raw)



In article <33575FD0.41C67EA6@hercii.mar.lmco.com>, "Angelo A. Keene"
<akeene@hercii.mar.lmco.com> wrote:

>If I have two Ada83 packages, defined as follows -- what are the 
>differences between the two, if any?  Would a user of this package
>not have access to the 'SIZE function now?
>
>package Test_Types_One is

[snip]

>package Test_Types_Two is

[snip]


>While building a short test package, I accidentally ended up with a
>package in the second form, which compiles successfully -- but after
>looking at it, I started thinking about the implications of what I
>wrote -- looking at my available references, I can't determine
>if the second form would have any useful meaning or not.

There's no difference between the two packages.  And you can always take
the 'Size of something, even a private type.

There's a debate about this very issue among Ada programmers.  Some like to
push the rep specs off into the private region, arguing that a client
shouldn't really care.  Others (myself among them) believe that the rep
spec should be in the public part, because the representation is an
essential characteristic of the type.

You only do rep specs when you're doing some kind of I/O - either to
another language or to an external hardware device.  Since this is a
low-level thing, you don't need to bother with any more abstraction by
putting the rep spec in the private part.

The time when it does matter is when you declare an object of the type in
the same package as the type.  Ada 83 calls this a "forcing occurance" and
Ada 95 a "freezing point."  At the point of declaration of the object, the
representation must be known, so you'd have to have already used the rep
spec.

Matt

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: Ada 83 - Rep clause inside private area question
  1997-04-20  0:00 ` Matthew Heaney
@ 1997-04-20  0:00   ` Robert Dewar
  0 siblings, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1997-04-20  0:00 UTC (permalink / raw)



matthew Heaney said

<<You only do rep specs when you're doing some kind of I/O - either to
another language or to an external hardware device.  Since this is a
low-level thing, you don't need to bother with any more abstraction by
putting the rep spec in the private part.
>>


This is quite wrong. There are many reasons for using rep clauses (I assume
that Matthew means rep clauses wwhen he says rep specs -- this is a very
common bit of incorrect terminology).

Examples are a small clause, which has an important effect on the semantics
and surely should be in the visible part.

Pack used to save space, this generally need NOT be in the public part
since it typically is not part of the logical interface.

A storage pool rep clause for an access type is certainly another example
of something that has nothing to do with I/O ..

Another example is

  for Reliable_Boolean use (2#01010101#, 2#10101010#) to get a Boolean
type whose representation is not single bit sensitive.

There are MANY other examples of the use of rep clauses which have nothing
to do with IO or interfacing, Matthews characterization is FAR too narrow.

He also said

<<There's a debate about this very issue among Ada programmers.  Some like to
push the rep specs off into the private region, arguing that a client
shouldn't really care.  Others (myself among them) believe that the rep
spec should be in the public part, because the representation is an
essential characteristic of the type.

>>


But this too may be affected by his far too narrow view of rep clauses.
Generally the issue of whether rep clauses go in the private part or not
is one of whether the rep clause is or is not part of the legitimate
interface which you want clients to be able to depend on. Sometimes the
answer is yes, sometimes the answer is no. Matthew said that his answer
is always yes, but an answer of yes is clearly inappropriate in some
of the above examples, and in many other examples.





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

end of thread, other threads:[~1997-04-20  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-18  0:00 Ada 83 - Rep clause inside private area question Angelo A. Keene
1997-04-20  0:00 ` Matthew Heaney
1997-04-20  0:00   ` Robert Dewar

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