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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: potential Ada feature - comments? Date: Wed, 11 Sep 2019 09:54:43 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:57130 Date: 2019-09-11T09:54:43+02:00 List-Id: On 2019-09-11 02:35, Matt Borchers wrote: > Yes, I agree that a nested block is an option but it looks crappy and is it okay to complain that everything has to be unnecessarily indented to accommodate this fairly common construct? "Finally" is IMO misleading. E.g. this would be wrong: declare File : File_Type; begin Open (File, ...); ... finally Close (File); end; The problem of exception handlers sharing parts of code does exist, but "finally" is no solution because it is too crude. In practice there are 2-3 different variants of finalization upon the subroutine exit. E.g. with exception vs. without exception. I think that the solution must be based on contracts, exception contracts in particular to make it possible to declare resources as local and statically checking their releasing. It also should be close to the place where the resource is claimed. One of many wrongs of "finally" is that it appears at the end of the block. It should rather be right after the call to Open, in my above. E.g. declare File : File_Type; begin Open (File, ...); -- Tell here to Close (File) afterwards! ... end; And, of course, as a proponent of OO and strongly typed approach, I would rather have some syntax sugar for light-weight ad-hoc controlled wrapper types. E.g. to stuff File_Type into and delegate all operations of File_Type to it without writing 2k lines of brain-dead code. P.S. Ada 83 is fine, but any language change would make it Ada 20XY anyway. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de