comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: A suggestion for resource management
Date: Sun, 22 Aug 2010 08:40:35 +0200
Date: 2010-08-22T08:40:34+02:00	[thread overview]
Message-ID: <1mnu86xdghhge$.eoigmedidpab$.dlg@40tude.net> (raw)
In-Reply-To: 8739u73c6l.fsf@mid.deneb.enyo.de

On Sat, 21 Aug 2010 23:09:38 +0200, Florian Weimer wrote:

> * Dmitry A. Kazakov:
> 
>> BTW, file handle File_Type should not be opened, it should be
>> constructed. There should be no invalid File_Type,
> 
> There are cases where you need the explicit Close operation, so you
> still end up with an invalid state.

It is difficult to construct such cases. One I can remember is the socket
closed from outside to break blocking recv. 

> How would you handle an exception raised by construction, without
> extending the handler to cover undue regions of code?

Roll back everything elaborated above and propagate.

>>> There are some cases where the destructor solution doesn't really
>>> apply.  For instance, the cleanup operation might need two parameters,
>>> one denoting the object, and a second one decribing where to put it.
>>
>> I would use mix-in in such rare cases. However, I try to avoid clean-ups.
>> It is a bad pattern.
> 
> And you suggest to use Finalize procedures instead?  Hmm.

Yes, it requires a bit more up front work, but it always pays off. It is
much simpler to maintain.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2010-08-22  6:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-21 16:20 A suggestion for resource management Florian Weimer
2010-08-21 19:07 ` Dmitry A. Kazakov
2010-08-21 19:47   ` Florian Weimer
2010-08-21 20:53     ` Dmitry A. Kazakov
2010-08-21 21:09       ` Florian Weimer
2010-08-22  6:40         ` Dmitry A. Kazakov [this message]
2010-08-23 23:22         ` Randy Brukardt
2010-08-21 20:34 ` Niklas Holsti
2010-08-21 21:01   ` Florian Weimer
2010-08-22 10:53     ` Niklas Holsti
2010-08-22 15:29       ` Florian Weimer
2010-08-22 16:12       ` Florian Weimer
2010-08-23 12:25         ` Niklas Holsti
2010-09-04 19:09           ` Florian Weimer
2010-09-07 10:14             ` Niklas Holsti
2010-08-22 11:32     ` Georg Bauhaus
2010-08-23 23:37       ` Randy Brukardt
2010-08-22 13:09 ` stefan-lucks
2010-08-22 14:30   ` Florian Weimer
2010-08-22 15:09   ` Florian Weimer
replies disabled

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