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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.swapon.de!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: storage error: stack overflow Date: Thu, 20 Aug 2015 15:48:42 -0500 Organization: JSA Research & Innovation Message-ID: References: <87k2srf1j8.fsf@theworld.com> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1440103723 13039 24.196.82.226 (20 Aug 2015 20:48:43 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 20 Aug 2015 20:48:43 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:27536 Date: 2015-08-20T15:48:42-05:00 List-Id: "Bob Duff" wrote in message news:87k2srf1j8.fsf@theworld.com... > "Jeffrey R. Carter" writes: > >> On 08/18/2015 05:23 AM, hreba wrote: >>> >>> I need an access type because in my real program TB is a tagged type and >>> I need >>> class-wide variables. >> >> You do not /need/ access types for this. Avoiding them requires some >> thought, >> but that's what S/W engineers do. > > I don't think it's fair to say that people who use access types > (i.e. pointers) aren't proper "S/W engineers". It's true that Ada > doesn't require pointers in many cases where other languages do. > But Ada still requires pointers if the class-wide variable > needs to change its tag. And pointers are required for recursive > data structures. Etc. > > I think what you and Randy have been saying (or should have been?) > is more like: > > 1. Try to avoid using pointers. > > 2. When you have to use them, try to encapsulate. > > 3. When possible, use the encapsulations already provided by the > language (i.e. the Ada.Containers). > > But there are all sorts of reasons why Ada.Containers might not be > suitable, so in those cases, you WILL use pointers, preferably > encapsulated. But that's different from saying "never use pointers" > (or "never use access types"). I say "never* use access types in the visible part of a package specification". And do what you have to implement that specification. Bodies of any good abstraction tend to turn into a groddy mess (especially once performance considerations get into the mix). That doesn't mean that the specification (the interface) of the abstract has to also be a groddy mess! The problem with putting access types in a specification is that you are then dictating how the client does storage management (they can no longer let a container or other abstraction do the management for them). That's the worst possible situation, letting the client decide on the optimal storage management for their uses is preferable, and the alternative of managing the storage within the abstraction is likely better as well. * As with all programming rules, there never is an absolute rule. There probably is some case where putting an access type into a specification would be better than trying to work around it. If you have a strong justification for doing so (one that does not appeal to knowledge of some other programming language!!), then go ahead (and document the reasoning). We had to use one in Claw because we needed a version of the Parent function that had reference semantics for its return. (I recall that without that, some operation became an infinite regress of copying.) I agonized about that for weeks, but couldn't find a better solution. (The solution ended up being an encapsulated access value that was part of inspiration for generalized references and how they're used in the containers. We could have done that a lot better in Ada 2012, but there still would be an access type.) Randy.