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!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool3.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> <18bfxkfl1kjy0$.4vebp50shxrp$.dlg@40tude.net> <8739u73c6l.fsf@mid.deneb.enyo.de> Date: Sun, 22 Aug 2010 08:40:35 +0200 Message-ID: <1mnu86xdghhge$.eoigmedidpab$.dlg@40tude.net> NNTP-Posting-Date: 22 Aug 2010 08:40:34 CEST NNTP-Posting-Host: dd3e4cda.newsspool3.arcor-online.net X-Trace: DXC=ISkneoNENSUAX0F2i> On Sat, 21 Aug 2010 23:09:38 +0200, Florian Weimer wrote: > * Dmitry A. Kazakov: > >> BTW, file handle File_Type should not be opened, it should be >> constructed. There should be no invalid File_Type, > > There are cases where you need the explicit Close operation, so you > still end up with an invalid state. It is difficult to construct such cases. One I can remember is the socket closed from outside to break blocking recv. > How would you handle an exception raised by construction, without > extending the handler to cover undue regions of code? Roll back everything elaborated above and propagate. >>> 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. > > And you suggest to use Finalize procedures instead? Hmm. Yes, it requires a bit more up front work, but it always pays off. It is much simpler to maintain. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de