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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a6b:2712:: with SMTP id n18-v6mr6570738ion.90.1530994795610; Sat, 07 Jul 2018 13:19:55 -0700 (PDT) X-Received: by 2002:aca:4787:: with SMTP id u129-v6mr3331346oia.4.1530994795410; Sat, 07 Jul 2018 13:19:55 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!feeder4.usenet.farm!feed.usenet.farm!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!85.12.16.69.MISMATCH!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!g2-v6no1773618itf.0!news-out.google.com!l67-v6ni5221itl.0!nntp.google.com!g2-v6no1773610itf.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 7 Jul 2018 13:19:55 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=213.108.152.51; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S NNTP-Posting-Host: 213.108.152.51 References: <856189aa-fa00-4960-929e-174f352310ad@googlegroups.com> <3701bf07-89a5-4cb0-a704-5aebb589ca79@googlegroups.com> <2f5e4ce0-94e8-4b94-9da7-045ec90a9b22@googlegroups.com> <18554067-1382-4b43-a832-2d27aa5117d7@googlegroups.com> <8dc19505-b68a-403c-a164-f1de1864f3f1@googlegroups.com> <559657f8-bbf4-4a70-9449-f85bc98d6c6b@googlegroups.com> <590d4672-4aef-42a5-823c-57ccd291115a@googlegroups.com> <8de6b5ba-25ab-4d46-b80c-1544f43a9b05@googlegroups.com> <670baa25-a987-45a0-991f-ec3aa2878233@googlegroups.com> <6acaa855-2508-49cc-a03f-16c6e00c91da@googlegroups.com> <87h8lcuesk.fsf@nightsong.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Teaching C/C++ from Ada perspective? From: Maciej Sobczak Injection-Date: Sat, 07 Jul 2018 20:19:55 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3900 X-Received-Body-CRC: 2920513495 Xref: reader02.eternal-september.org comp.lang.ada:53721 Date: 2018-07-07T13:19:55-07:00 List-Id: > Make the other package a child. It's cheating. :-) The problem is - the "private" in Ada package spec does not correspond to "= private" in C++ classes, but rather to "protected". You can extend a C++ cl= ass with a derived class and access protected stuff from there - this is th= e equivalent of creating a child package in Ada in order to access the not-= so-private parts from the parent. In other words, this Ada idiom is replicable in C++ with the use of "protec= ted" parts. It is the "private" in C++ that has no equivalent in Ada. That is: class MyCppClass { public: // ... // this is what you have in the public part of Ada spec protected: // ... // this is what you have in the "private" part of Ada spec, // you can access this part from derived classes or children packages private: // ... // no, you don't have this level of privacy in Ada (!) // and definitions in your package body are not exactly equivalents }; > I often have packages with procedures declared in the private part for > the benefit of children (only). As shown above, C++ programmers put this kind of stuff under the "protected= " tag. When it comes to friends, they are implemented in Ada in terms of putting m= ultiple types within the same package, so that they can see each other. I a= dmit that I like this idiom more than than the friendship in C++, even if f= riends are more flexible (they can make much longer spans, but I would say = it is a privacy equivalent of goto, with the same long-term consequences). --=20 Maciej Sobczak * http://www.inspirel.com