comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: derived formal types and known discriminants
Date: Mon, 3 Jul 2017 21:29:15 -0500
Date: 2017-07-03T21:29:15-05:00	[thread overview]
Message-ID: <ojeuhs$g84$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: a1bd4695-00ff-49a8-a07a-84ebdb043202@googlegroups.com

<sbelmont700@gmail.com> wrote in message 
news:a1bd4695-00ff-49a8-a07a-84ebdb043202@googlegroups.com...
On Friday, June 30, 2017 at 2:10:01 PM UTC-4, Randy Brukardt wrote:
>> Sure, but they're very inflexible in that usage (as bad or worse than the
>> original unconstrained types). So I tend to view these as an either/or
>> proposition: untagged, mutable types with discriminants, or tagged types
>> without discriminants. Again, YMMV.

>At the risk of having some of the other thread's shade thrown in here, 
>aren't
>tagged discriminated records the de facto way of doing initialization? 
>That is,
>extending a Controlled type and then using discriminants in place of ctor 
>arguments?

I've heard of people trying to use that sort of thing, but I find it too 
inflexible (in that you have to declare an object at exactly the right 
place). Thus most of my types default-initialize to an "invalid" state, and 
there is one or more "Create" or "Open" routines to make a usable version. A 
bit more complicated, but it allows the initialization to occur anywhere 
(not necessarily where the object is declared, which usually is picked to 
give the proper lifetime for the object - that is, the destruction point) 
and the initialization can have arbitrary parameters.

You do need a check (or precondition) for validity for most operations, but 
that should be optimizable (if written as a precondition with an appropriate 
stable property [in Ada 202x]). So it shouldn't cost much if anything at 
runtime.

This after all is the model of file objects in Ada 83, and it works well for 
them and many other things.

                                             Randy.


  parent reply	other threads:[~2017-07-04  2:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23  0:45 derived formal types and known discriminants sbelmont700
2017-06-23 17:26 ` Randy Brukardt
2017-06-29 14:15   ` sbelmont700
2017-06-29 14:39     ` Dmitry A. Kazakov
2017-06-29 17:40       ` Robert Eachus
2017-06-30  1:10     ` Randy Brukardt
2017-06-30  7:24       ` Dmitry A. Kazakov
2017-06-30 18:09         ` Randy Brukardt
2017-07-04  0:30           ` sbelmont700
2017-07-04  1:36             ` gautier_niouzes
2017-07-04  2:29             ` Randy Brukardt [this message]
2017-07-04  7:09             ` Dmitry A. Kazakov
2017-07-04 17:34               ` Shark8
2017-07-03 17:24 ` Jere
replies disabled

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