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.99.107.136 with SMTP id g130mr6780702pgc.14.1498293270751; Sat, 24 Jun 2017 01:34:30 -0700 (PDT) X-Received: by 10.157.47.207 with SMTP id b15mr289682otd.20.1498293270696; Sat, 24 Jun 2017 01:34:30 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!f20no534167itb.0!news-out.google.com!k7ni924itk.0!nntp.google.com!f20no534164itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 24 Jun 2017 01:34:30 -0700 (PDT) In-Reply-To: <88e2f18a-0786-4303-a5b8-fe82e8c81dcb@googlegroups.com> 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: <1ac5a44b-4423-443a-a7bb-2864d9abe78f@googlegroups.com> <1498048151.20885.28.camel@obry.net> <96174ea5-852d-44e9-8535-7c1eb24d5326@googlegroups.com> <8d3aff06-82df-485f-89e5-a50c326aab05@googlegroups.com> <66aa262e-2ac9-4016-b32d-e9fee14779e1@googlegroups.com> <88e2f18a-0786-4303-a5b8-fe82e8c81dcb@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Ada Annoyances From: Maciej Sobczak Injection-Date: Sat, 24 Jun 2017 08:34:30 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:47096 Date: 2017-06-24T01:34:30-07:00 List-Id: > > There is one place where Ada is broken in this regard - Controlled type= s. These should not be tagged. C++ got it right here. >=20 > Out of curiosity, why should controlled types not be tagged? Because tagging (like v-table in C++) is a language design artefact that en= ables dynamic binding, which has its costs and has nothing to do with autom= ated lifetime management. These concepts are orthogonal and there is no nee= d to entangle them together. This has practical implications. In C++ the auto_ptr or scoped_ptr (or simi= lar) wrapper has literally zero cost, both in space and in time. If the raw= pointer has 4 bytes (on a 32-bit machine), the scoped_ptr wrapper will hav= e 4 bytes, too. Ada imposes unnecessary cost - again, both in space and tim= e. > And how is C++ much different - other than that you can make destructors = non-virtual In a class that is not intented for use in a class hierarchy (like said RAI= I wrappers) the destructor should *not* be virtual, as there is no reason f= or it to be. > (and therefore never dynamically dispatch, though I think the advice I us= ually see is to make almost all destructors virtual to avoid the case where= the wrong destructor gets called). This is not a complete advice. If the class is not part of any hierarchy, t= here is only one destructor and always the right one will be called. > Again, I'm not quite sure I follow you here. What do you mean by "not com= patible with the lifetime of its parts"? In C++ when the object of derived class is constructed, its base class cons= tructor is called first and at that time the object is considered to have t= he Base dynamic type, which makes sense, as the derived parts have not yet = been initialized (they will be initialized in the Derived constructor, whic= h will happen later). Only after the base constructor finishes, the dynamic= type of the object is "promoted" to Derived. This means that virtual calls= within the Base constructor will never dispatch to Derived variants, which= is safer, as it prevents accidental access to not-yet-initialized parts of= the object from virtual functions. We say that from within constructors (a= nd destructors, where the same process goes in the reverse direction) the s= tatic type is equal to the dynamic type of the object. Ada does not have this feature and diaptching calls can access uninitialize= d components from derived parts by means of dispatching to the not-yet-born= parts of the object. In this sense and this particular context, C++ offers better and stronger (= !) type safety than Ada. --=20 Maciej Sobczak * http://www.inspirel.com