From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: A suggestion for resource management
Date: Sat, 21 Aug 2010 22:53:01 +0200
Date: 2010-08-21T22:53:01+02:00 [thread overview]
Message-ID: <18bfxkfl1kjy0$.4vebp50shxrp$.dlg@40tude.net> (raw)
In-Reply-To: 87d3tb7npi.fsf@mid.deneb.enyo.de
On Sat, 21 Aug 2010 21:47:05 +0200, Florian Weimer wrote:
> * Dmitry A. Kazakov:
>
>> On Sat, 21 Aug 2010 18:20:29 +0200, Florian Weimer wrote:
>>
>>> procedure Test_External_Formats is
>>> ...
>>> COBOL_File : File_Type;
>>> ...
>>>
>>> begin
>>> Open (COBOL_File, Name => "Some_File");
>>> pragma Scoped (Close (COBOL_File));
>>>
>>> loop
>>> ...
>>> exception
>>> when End_Error => ...
>>> end Test_External_Formats;
>>
>> What is wrong with having a destructor for File_Type? If the language is to
>> be extended why not to fix that first?
>
> You can't always change libraries in that way. Adding destructors has
> both syntactic and run-time overhead.
I don't see why. Without class-wide objects there is no overhead,
everything is statically known. Neither there is any syntactic overhead.
File_Type is extended just once and then used everywhere. In fact it is
your solution that has distributed overhead (and error-prone too), because
the pragma has to be used everywhere a file is opened. BTW, file handle
File_Type should not be opened, it should be constructed. There should be
no invalid File_Type, at least the library should not encourage them as the
Ada library does and in your example follows.
> The run-time overhead can be
> minimized by a sufficiently advanced compiler (perhaps relying on
> whole-program optimization to detect the lack of task aborts). I'm
> more concerned with the syntactic overhead.
>
> 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.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2010-08-21 20:53 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 [this message]
2010-08-21 21:09 ` Florian Weimer
2010-08-22 6:40 ` Dmitry A. Kazakov
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