From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7fcf9180e7ba7ab1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!news2.arglkargh.de!news.n-ix.net!news.belwue.de!rz.uni-karlsruhe.de!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: Florian Weimer Newsgroups: comp.lang.ada Subject: Re: A suggestion for resource management Date: Sat, 04 Sep 2010 21:09:32 +0200 Organization: 1&1 Internet AG Message-ID: <87k4n14977.fsf@mid.deneb.enyo.de> References: <8762z4gcoi.fsf@mid.deneb.enyo.de> <8darikF1b0U1@mid.individual.net> <87eidr3cje.fsf@mid.deneb.enyo.de> <8dcdu1F4v9U1@mid.individual.net> <878w3yhbi2.fsf@mid.deneb.enyo.de> <8df7ksFu5fU1@mid.individual.net> NNTP-Posting-Host: p4fe389fb.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: online.de 1283627372 18083 79.227.137.251 (4 Sep 2010 19:09:32 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Sat, 4 Sep 2010 19:09:32 +0000 (UTC) Cancel-Lock: sha1:dWWAzIuficOTzjFWfThdu12Zb24= Xref: g2news1.google.com comp.lang.ada:13949 Date: 2010-09-04T21:09:32+02:00 List-Id: * 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.