From: Florian Weimer <fw@deneb.enyo.de>
Subject: Re: A suggestion for resource management
Date: Sun, 22 Aug 2010 17:29:54 +0200
Date: 2010-08-22T17:29:54+02:00 [thread overview]
Message-ID: <87occuhdhp.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: 8dcdu1F4v9U1@mid.individual.net
* Niklas Holsti:
>> In a sense, it's just repeating what Unchecked_Deallaction does behind
>> the scenes.
>
> I don't understand your comment at all. An instance of
> Unchecked_Deallocation is explicitly executed where it is called, not
> at some later point in time, and no pragma is involved. Or do you mean
> Finalize for controlled types?
Exactly, Unchecked_Deallocation arranges for calls to a somewhat
non-obvious set of Finalize subprogramms.
> However, if the evaluate-and-save is *only* equivalent to renaming,
> you can get weird effects where a scalar variable seems to have
> different values at different places in the parameter list. For
> example, consider (using the pragma syntax):
Oh, so scalars need to be copied after all. 8-)
> Moreover, what happens if an actual parameter is a function call?
> Should the function be called at the point of the "pragma Scoped", or
> later?
At the point of the pragma.
> I think the clearest solution to point (4) is to say that all of the
> "scheduled" code is evaluated and executed later (before the "end").
>> The branches of an if statement aren't a
>> handled_sequence_of_statements, so it's not allowed.
>
> Ok, I misunderstood your suggestion: you would only allow pragma
> Scoped on the "top" level in a handled_sequence_of_statements.
>
> But why make this limitation? It seems to me not unlikely that some
> application may conditionally Open a COBOL_File, and then a similarly
> conditional Close should occur at the end. One could even let "pragma
> Scoped" be used in loops and execute the clean-up code just before the
> present iteration of the loop ends.
There is an ambiguity whether the cleanup will occur at the end of the
sequence_of_statements, or at the end of some outer scope. As a case
in point, in the "if" case, you suggest to prefer outer scope, but for
the loop case, you want local cleanup. I couldn't decide which one is
the right approach, so I made both illegal.
>> I'm not sure if it still can
>> be considered good language design. Most languages which strive for
>> exception safety are gradually moving to different constructs (even
>> Java).
>
> That could be an argument. Can you present these "different
> constructs" here as examples that we could compare to "finally" and to
> your proposal?
Python:
<http://docs.python.org/reference/compound_stmts.html#with>
<http://www.python.org/dev/peps/pep-0343/>
Java:
<http://blogs.sun.com/darcy/entry/project_coin_updated_arm_spec>
C# (which contained it from the start):
<http://msdn.microsoft.com/en-us/library/yh598w02%28VS.80%29.aspx>
Go (with some peculiar semantics):
<http://golang.org/doc/go_spec.html#Handling_panics>
Perl 6 apparently has LEAVE (as a more dynamic variant of END), but I
don't know if it is actually used.
For evidence that try-finally doesn't work, it's instructive to run a
suitable static analyzer on a code base for the first time. Even if
the developers are competent, you'll find rule violations, several of
them caused by a desire to reduce syntactic overhead.
next prev parent reply other threads:[~2010-08-22 15:29 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
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 [this message]
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