comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Accessing finalized values
Date: Mon, 6 May 2013 19:51:58 -0500
Date: 2013-05-06T19:51:58-05:00	[thread overview]
Message-ID: <km9j7h$es4$1@munin.nbi.dk> (raw)
In-Reply-To: 56ae2d39-e3a1-4d3e-b9a1-8d4aa435ad8a@googlegroups.com

<sbelmont700@gmail.com> wrote in message 
news:56ae2d39-e3a1-4d3e-b9a1-8d4aa435ad8a@googlegroups.com...
On Monday, May 6, 2013 5:52:18 AM UTC-4, Dmitry A. Kazakov wrote:

>> Finalize is a hack.

I disagree with this...

>The more I delve into controlled types, the more I'm starting to come to 
>that
> conclusion.  This means, in general, that every controlled type must track 
> the
> state of its finalization and conditionally release resources (to 
> side-step the
> non-limited multiple finalization issue), as well as add a 'not 
> Is_Finalized'
> precondition to every single operation (to avoid access after 
> finalization)?
> Yuck.

...but disagree with this. And the main reason is that you have to be able 
to handle "non-open" objects in any case (consider files -- you have to 
already have some sort of check for an unopen file). So there is no problem 
to using that same check for objects that have been finalized.

For instance, in Claw, we have "invalid" objects, which is any object that 
exists, but has not yet been created or has previously been closed (which 
included finalization). Finalization releases resources making the object 
invalid. Every operation (other than Create, Close, and Finalize) have to 
check for whether the object is valid, and raise an exception if it is not. 
Care must be taken to avoid referencing any components if the object is 
invalid. There's certainly some level of complication to that, but it's 
unavoidable for any abstraction that has something like Create and/or Close.

It might be more of a problem for abstractions that don't have "Close", but 
even there there is usually an "empty" abstraction which also works fine. 
For instance, the Ada containers work this way: they're initialized to 
empty, and end up empty after finalization, and that's sufficient if the 
implementation can avoid using an extra resources for an empty container. 
(If you can't do this, the language requires raising an exception on use, so 
you'd have to have an extra flag and check.)

To summarize, it's a level of complication, but its one you're almost 
certainly going to have to deal with anyway. The main problem is that it 
makes most simplistic examples wrong - real examples need checks everywhere 
anyway (if they're a well-designed Ada abstraction).

                                              Randy.




-sb 


      reply	other threads:[~2013-05-07  0:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-02 21:00 Accessing finalized values sbelmont700
2013-05-02 22:47 ` Adam Beneschan
2013-05-03 22:36 ` Randy Brukardt
2013-05-05 15:00   ` sbelmont700
2013-05-06  5:45     ` J-P. Rosen
2013-05-06  8:59     ` Stephen Leake
2013-05-06  9:52     ` Dmitry A. Kazakov
2013-05-06 20:05       ` sbelmont700
2013-05-07  0:51         ` Randy Brukardt [this message]
replies disabled

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