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!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Tagged type abuse Date: Thu, 18 Dec 2014 17:10:37 -0600 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1418944238 8563 24.196.82.226 (18 Dec 2014 23:10:38 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 18 Dec 2014 23:10:38 +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:24128 Date: 2014-12-18T17:10:37-06:00 List-Id: "Jeffrey Carter" wrote in message news:m6v154$r9t$1@dont-email.me... > On 12/18/2014 04:26 AM, Natasha Kerensikova wrote: >> >> I find myself using more and more tagged types for reasons that have >> nothing to do with tagging, mostly the prefix notations (when it helps >> readability and when a function call is conceptually accessing a record >> element but with a hidden concrete implementation) and the passing by >> reference. >> >> However, I still feel guilty about it, like I'm abusing a feature >> unrelated to what I wish to accomplish. >> >> What would you recommend to appease such feelings? > > There are three reasons I use tagged types: > > 1. To obtain finalization > > 2. To avoid explicit pointers in self-referential types > > 3. To obtain Object.Operation notation I think that Jeff is saying that not everyone thinks dynamic dispatching is relevant. But tagged types still can be useful. Note that in pre-2012 Ada, you needed to use tagged types get "=" to work right vis-a-vis composition. (Ada 2012 extended that to all record types, which of course means that some programs that expect the wrong answer will break. But in most cases, the change will fix bugs rather than create them.) I don't use dynamic dispatching much (outside of Claw anyway), but I sometimes use inheritance to inherit implementations (rather than having to duplicate them all over, with the corresponding maintenance headache). I'd probably use tagged types to get prefix notation, but I'd have to implement it in Janus/Ada first. :-) Anyway, I wouldn't worry about it. Tagged types cost about the same as regular record types (the only difference is the waste of space for the tag, which only matters for tiny records) unless you use T'Class. So do what makes you program work better. (We couldn't make cursors in the containers be tagged, thus you can't use prefixed notation to do various reading operations on the containers. One more reason out of many that I think every container operation should have had a container parameter. [Another reason is that preconditions make much more sense if the container passed to an operation has a name.] But of course there is as many container designs as there are programmers -- perhaps more -- and the big value was picking one. There is no way it could have been perfect for every use anyway.) Randy.