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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b8b8a54001adc4d2 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Nick Roberts Newsgroups: comp.lang.ada Subject: Re: Possible Ada deficiency? Date: Fri, 31 Dec 2004 23:23:49 +0000 Message-ID: References: <1104516913.718856.94090@z14g2000cwz.googlegroups.com> Content-Type: text/plain; charset=us-ascii X-Trace: individual.net +YCG+yiKbFtrKoGh/pDDSgY9DH6DoBM6t9U/HJPqDSd/kYwwU= X-Orig-Path: not-for-mail User-Agent: Gemini/1.45d (Qt/3.3.2) (Windows-XP) Xref: g2news1.google.com comp.lang.ada:7361 Date: 2004-12-31T23:23:49+00:00 List-Id: danmcleran@hotmail.com wrote: > I would like to know if anyone else thinks that the inability to hide > private information from child packages is a deficiency in Ada95. I am > discussing ways to do this on another thread, (See Private area and child > packages), but it seems wrong that one has to go through a bunch of > machinations to do something like this. Wouldn't a language construct for > this be advantageous? Perhaps the ability to declare a 'body type' within a private part would do the trick: package Some_Package is type Fairly_Secret_Type is private; private body type Really_Secret_Stuff is record ...; end record; type Fairly_Secret_Type is record ...; Secret: Really_Secret_Stuff; end record; end Some_Package; This would prevent the type Really_Secret_Stuff from being visible anywhere but in the body of the package Some_Package (so that components of the component Secret would be hidden from private children of Some_Package). Unfortunately, it is now too late for any further changes to Ada 2005. This might be something to be considered at the next revision. Personally, I've often found it useful to use an incomplete type declaration in the private part to completely isolate the actual contents of a visible type from everything outside the package body. package P is type T is private; ... private type Innards_Bearer(<>); type Innards is access Innards_Bearer; type T is record Data: Innards; end record; end P; package body P is ... type Innards_Bearer is record ... -- actual contents here end record; ... end P; Obviously this technique requires explicit allocation (and maybe deallocation), and the inefficiency of a (further) level of dereferencing, but these are usually not a significant problem (and are confined to the body). The additional advantage is that the actual contents can be changed within the body, so not clobbering the specification (or therefore, more importantly, any of its dependants). This technique will hide the actual contents from the private children of the package. It comes close to achieving what you suggest, Dan. I haven't read the whole of the other thread you mention, so perhaps this technique has already been mentioned there. -- Nick Roberts