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: a07f3367d7,cb04cee6116c8ced X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!o3g2000yqb.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Package's private parts and protected types Date: Mon, 8 Feb 2010 00:30:12 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <7ff3810f-3ee3-4f39-a54c-933ad7d0655c@36g2000yqu.googlegroups.com> NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1265617813 30454 127.0.0.1 (8 Feb 2010 08:30:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 8 Feb 2010 08:30:13 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o3g2000yqb.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8965 Date: 2010-02-08T00:30:12-08:00 List-Id: On Feb 8, 4:30=A0am, Hibou57 (Yannick Duch=EAne) wrote: > Hi all out there, > > Whenever a protected type is declared, all of its specification has to > be defined at once and not private stuff can be delay (like "type ... > is private" would allow). If this protected type is to hold something > which is not to be public, the only way to do as far I'm able to do, > is to wrap it in a private type as a record component. > > package P > > =A0 =A0type A_Type is limited private; > =A0 =A0-- Must be limited, to be able to hold a limited component. > > =A0 =A0function Value (A : A_Type) return Value_Type; > =A0 =A0-- Value_Type defined somewhere else. > > =A0 =A0procedure Do_Something (A : in out A_Type); > =A0 =A0-- Potentially blocking. > =A0 =A0-- Obviously, there are comments to assert such things, > =A0 =A0-- but I would prefer it to be formally stated. > > private > > =A0 =A0protected type B_Type is > =A0 =A0-- Cannot move it in the public part, due > =A0 =A0-- to a feature (Set_Value) which must not be public. > =A0 =A0 =A0 function Value return Value_Type; > =A0 =A0 =A0 -- Accessed via the corresponding method on A_Type. > =A0 =A0 =A0 procedue Set_Value (New_Value : in Value_Type); > =A0 =A0 =A0 -- The A_Type does not have such a corresponding > =A0 =A0 =A0 -- method : we want it to remains private. > =A0 =A0 =A0 procedure Do_Something; > =A0 =A0 =A0 -- Accessed via the corresponding method on A_Type. > =A0 =A0 =A0 -- B_Type being protected, this means this is > =A0 =A0 =A0 -- a potentially blocking operation. > =A0 =A0end B_Type; > > =A0 =A0type A_Type is limited record > =A0 =A0 =A0 B : B_Type; > =A0 =A0end record; > > end P; > > Then, implementation of methods on A_Type will then simply pass > control to the corresponding ones of its B component. All of this, > just to hide something which is not to be part of the public > specification. > > I don't like it, because it does not any more publicly shows that > things relies on a protected object. > > Was this a desired consequence when this part of Ada was designed ? > > Do someone know a reason ? > > Is there something I'm doing here I should not do ? This is true of task types too. We take the view that if something was a task/protected or not should be hidden from a user (e.g. we may change the behaviour from being task based/not protected, so we abstract away that information). The associated 'rule' for callers is that they can't assume that calls to any operation don't block - but that's true of calling pretty much any package anyway. I wonder if there is room for "pragma (Not_)Blocking"?...Not just as a visual aid but maybe it could also be used extend the usage of "pragma Detect_Blocking" to wrappers for "foreign languages". Cheers -- Martin