From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e977cd3ab4e49fef X-Google-Attributes: gid103376,public From: Ken Garlington Subject: Re: Question about record rep spec placement Date: 1997/01/22 Message-ID: <32E6A985.6C4B@lmtas.lmco.com>#1/1 X-Deja-AN: 211567417 references: <5c36u6$khm@zeus.orl.mmc.com> content-type: text/plain; charset=us-ascii organization: Lockheed Martin Tactical Aircraft Systems mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 3.01 (Win95; U) Date: 1997-01-22T00:00:00+00:00 List-Id: 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