comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Tagged type abuse
Date: Thu, 18 Dec 2014 17:10:37 -0600
Date: 2014-12-18T17:10:37-06:00	[thread overview]
Message-ID: <m6vmte$8bj$1@loke.gir.dk> (raw)
In-Reply-To: m6v154$r9t$1@dont-email.me

"Jeffrey Carter" <spam.jrcarter.not@spam.not.acm.org> 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.





  reply	other threads:[~2014-12-18 23:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-18 11:26 Tagged type abuse Natasha Kerensikova
2014-12-18 13:01 ` Dmitry A. Kazakov
2014-12-18 16:59 ` Jeffrey Carter
2014-12-18 23:10   ` Randy Brukardt [this message]
2014-12-19 12:42     ` Michael B.
2014-12-20  0:07       ` Randy Brukardt
2014-12-20 12:39         ` Michael B.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox