comp.lang.ada
 help / color / mirror / Atom feed
From: Ken Garlington <GarlingtonKE@lmtas.lmco.com>
Subject: Re: Question about record rep spec placement
Date: 1997/01/22
Date: 1997-01-22T00:00:00+00:00	[thread overview]
Message-ID: <32E6A985.6C4B@lmtas.lmco.com> (raw)
In-Reply-To: 5c36u6$khm@zeus.orl.mmc.com


Bob Gilbert wrote:
> 
> I too agree with Ken's reasons for putting rep clauses in the private
> part (to support a documentation tool and because the client should
> not have to be bothered with the details of the rep clause), but it
> seems to me if you don't want the client to know about the details of
> the type, why not go ahead and make the type private?  This is where
> I find it odd to place only the rep clause in the private part for a
> type which is not private (as in Ken's example).

Maybe a simple example would help:
---
package Device_IO is

  type Priority_Type is ( Normal, Urgent );
  type Port_Type is range 0 .. 2#111#;
  type Data_Type is range 0 .. 16#FFF#;
  
  type Message_Type is record
    Priority : Priority_Type := Normal;
    Port     : Port_Type;
    Data     : Data_Type;
  end record;
  
private

  for Message_Type use record
    Priority at 0 range 0 .. 0;
    Port     at 0 range 1 .. 3;
    Data     at 0 range 4 .. 15;
  end record;
  
  for Message_Type'Size use 16;

end Device_IO;
---

The way we intend a clients to read this is: You can
assume that a Message has components Priority, Port, and
Data, with the types shown. However, there are no guarantees
as to the size of a Message, the placement of components
within that message, the number of bits each component will
use, etc. being stable from release to release. (In some
cases, of course, you can use attributes to determine the
current values, but it's up to the client to protect himself
from changes in those attribute values.)

What happens if I leave off the word private? In that case,
I will be giving tacit permission for the user to do
things like use Unchecked_Conversion to convert between
Messages and 16-bit integers (as an example). You could argue that
this is poor programming practice, but as least as far as
how I understand the idea of programming by contract, if
you put it in the visible part of the package spec, the assumption is
that the client can take advantage of this information.

I could certainly declare a Message as a private type, and
provide operations to manipulate its contents. However,
there are cases where I'm not really adding much to the
strength of the interface by adding the extra code.

--
LMTAS - The Fighter Enterprise - "Our Brand Means Quality"
For job listings, other info: http://www.lmtas.com or
http://www.lmco.com




  reply	other threads:[~1997-01-22  0:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-15  0:00 Question about record rep spec placement Ken Garlington
1997-01-15  0:00 ` Norman H. Cohen
1997-01-16  0:00   ` Ken Garlington
1997-01-17  0:00     ` Robert A Duff
1997-01-18  0:00       ` Ken Garlington
1997-01-15  0:00 ` Bob Gilbert
1997-01-16  0:00   ` Fergus Henderson
1997-01-17  0:00   ` Ken Garlington
1997-01-17  0:00     ` Bob Gilbert
1997-01-17  0:00       ` Robert A Duff
1997-01-17  0:00         ` Ken Garlington
1997-01-18  0:00           ` Robert A Duff
1997-01-18  0:00             ` Ken Garlington
1997-01-19  0:00               ` Robert A Duff
1997-01-21  0:00         ` Bob Gilbert
1997-01-22  0:00           ` Ken Garlington [this message]
1997-01-23  0:00             ` Art Schwarz
1997-01-25  0:00               ` Ken Garlington
1997-01-24  0:00             ` Bob Gilbert
1997-01-25  0:00               ` Ken Garlington
1997-01-20  0:00       ` Ken Garlington
1997-01-16  0:00 ` Jeff Creem
1997-01-16  0:00 ` Jerome Desquilbet
replies disabled

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