From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: potential Ada feature - comments?
Date: Wed, 11 Sep 2019 09:54:43 +0200
Date: 2019-09-11T09:54:43+02:00 [thread overview]
Message-ID: <qla985$2vb$1@gioia.aioe.org> (raw)
In-Reply-To: a1312e9e-0724-4e87-98da-a38c54784f03@googlegroups.com
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
next prev parent reply other threads:[~2019-09-11 7:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-10 17:52 potential Ada feature - comments? Matt Borchers
2019-09-10 19:13 ` Dmitry A. Kazakov
2019-09-11 0:35 ` Matt Borchers
2019-09-11 7:54 ` Dmitry A. Kazakov [this message]
2019-09-13 1:14 ` Matt Borchers
2019-09-11 16:00 ` G. B.
2019-09-11 9:55 ` fabien.chouteau
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox