comp.lang.ada
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
Subject: Re: A suggestion for resource management
Date: Sat, 04 Sep 2010 21:09:32 +0200
Date: 2010-09-04T21:09:32+02:00	[thread overview]
Message-ID: <87k4n14977.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: 8df7ksFu5fU1@mid.individual.net

* Niklas Holsti:

> That does not solve the basic problem, because then, in "pragma Scoped
> (Foo (X))", the value (old or new) of X that is (eventually) used in
> the call would depend on whether X is scalar or not, which would be
> very error-prone under maintenance.

Finalization of components is quite magic, too.

> Also, what if X is a private type defined in another package?
> Depending on its scalarity would break privacy.

That information already leaks during exception handling.

In retrospect, the construct suggested by Stefan (with the additional
tweak I mentioned) should work well enough, it just introduces a
pointless identifier.  Curiously, it shares many of the things you
criticize about pragma Scoped.

This succient notation was not possible in Ada 95, so I'm not too
embarrassed that I missed this option.

> By the way, Florian, in your original posting you said:
>
> Florian Weimer wrote:
>> Here's a proposal for a resource management pragma. It is similar
>> to the scope(exit) directive in D, the C++ scope guard idom, and
>> (to a lesser degree) Go's rescue statement.
>
> It seems to me that the Go "rescue" statement is Go's form of an
> exception handler/catcher, and not at all like pragma Scoped. I assume
> you meant the "defer" statement, Florian, is that right?

Yes, I keep confusing the Go terms.

> - Florian's proposal is unique in suggesting a "pragma" syntax. All
> the other languages use syntax that is made part of the core language
> and is not just a "compiler directive".

The idea was to implement it in an existing compiler if the semantics
are well-received.

>> 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.
>
> Concrete examples would be interesting.

In Java, I often see programmers using FileInputStream or Socket
without try-finally blocks, relying on the garbage collector to close
file descriptors.  Sorry, I can't be more specific than that.  I'll
try to remember to post a follow-up when I see something similar in an
open code base.



  reply	other threads:[~2010-09-04 19:09 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
2010-08-22 16:12       ` Florian Weimer
2010-08-23 12:25         ` Niklas Holsti
2010-09-04 19:09           ` Florian Weimer [this message]
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