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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.43.31.81 with SMTP id sf17mr2832001icb.4.1400874126902; Fri, 23 May 2014 12:42:06 -0700 (PDT) X-Received: by 10.50.143.1 with SMTP id sa1mr134478igb.12.1400874126829; Fri, 23 May 2014 12:42:06 -0700 (PDT) Path: backlog1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!hl10no4615355igb.0!news-out.google.com!qf4ni12380igc.0!nntp.google.com!c1no15380094igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 23 May 2014 12:42:06 -0700 (PDT) In-Reply-To: <29a09fe5-72c0-40e0-bf72-632c4a13232e@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: <29a09fe5-72c0-40e0-bf72-632c4a13232e@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <70638024-2a8b-45e1-aea4-5964f4416abf@googlegroups.com> Subject: Re: What is the difference of "with null record" and "with private"? From: Adam Beneschan Injection-Date: Fri, 23 May 2014 19:42:06 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:186581 Date: 2014-05-23T12:42:06-07:00 List-Id: On Friday, May 23, 2014 11:55:09 AM UTC-7, mockturtle wrote: > On Friday, May 23, 2014 8:21:21 PM UTC+2, Victor Porton wrote: > One could say that "with private" is used to hide the internal details of= your type and that if the extension is done with a "null record" there is = not much to hide. Actually, I cannot imagine a case where the fact that it = is public that the extension is null can cause loss of maintainability the = day some new fields are added. Nevertheless, usually I prefer the "with pr= ivate" form for uniformity. I can easily imagine a case. package Pack0 is type Base_Record is tagged record F1 : Integer; end record; end Pack0; package Pack1 is type An_Extension is new Base_Record with null record; type A_Private_Extension is new Base_Record with private; private type A_Private_Extension is new Base_Record with null record; end Pack1; ... procedure Proc is -- in some other package A1 : An_Extension :=3D (F1 =3D> 3); -- legal=20 A2 : A_Private_Extension :=3D (F1 =3D> 3); -- illegal begin=20 ... The point here is that when declaring an aggregate of type An_Extension, th= e program can count on the fact that the extension has no additional fields= , while for A_Private_Extension, it can't. **The fact that A_Private_Exten= sion has no additional fields is an implementation detail that is hidden fr= om the rest of the program.** It's not true that there is "nothing to hide= " ... the fact that there are no details is definitely something that may n= eed to be hidden. Suppose that you later change the implementation of Pack= 1 and decide to add some fields to A_Private_Extension. Since the implemen= tation details are hidden, you can change them without worrying that you wi= ll break something else in some other package far, far away. (This wouldn'= t be true if the declaration of A2 were legal.) And that's the whole purpo= se of "private" and the whole purpose of encapsulation in general--so that = hidden implementation details can be changed without worrying about having = to search every user of the package to see if it needs to change. -- Adam