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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!feeder.news-service.com!xlned.com!feeder5.xlned.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!87.79.20.105.MISMATCH!news.netcologne.de!ramfeed1.netcologne.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: A suggestion for resource management Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <8762z4gcoi.fsf@mid.deneb.enyo.de> <1q8io375n581c$.7mbvmavnyzyy$.dlg@40tude.net> <87d3tb7npi.fsf@mid.deneb.enyo.de> Date: Sat, 21 Aug 2010 22:53:01 +0200 Message-ID: <18bfxkfl1kjy0$.4vebp50shxrp$.dlg@40tude.net> NNTP-Posting-Date: 21 Aug 2010 22:53:01 CEST NNTP-Posting-Host: f941fb51.newsspool3.arcor-online.net X-Trace: DXC=jSoZKkWOJb@@k=MdN::NBIMcF=Q^Z^V3H4Fo<]lROoRA8kFT\^nE^;mI[6LHn;2LCVN[ 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