comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Matthews <ignored@ramatthews.free-online.co.uk>
Subject: Re: Ensuring postconditions in the face of exceptions
Date: Tue, 16 Mar 2010 19:25:34 +0000
Date: 2010-03-16T19:25:34+00:00	[thread overview]
Message-ID: <s7SdnaCcVPezRgLWnZ2dnUVZ8vBi4p2d@brightview.co.uk> (raw)
In-Reply-To: hnm188$rfh$1@tornado.tornevall.net

Jeffrey R. Carter wrote:

> Ludovic Brenta wrote:
>> 
>> The problem with that approach is that the processing of the Dirty
>> flag is no longer localized in the Refresh procedure which, in fact,
>> might as well disappear altogether; instead, each caller of Refresh
>> (or Visit) must now remember to handle exceptions and reset Dirty to
>> True accordingly.
> 
> With your code, the only way an exception can be raised is if the input
> value of Dirty is True. Since Dirty is not a parameter of Visit, the call
> to Visit presumably doesn't change Dirty. If so, you could eliminate the
> exception handler and have the desired functionality: Dirty would be True
> on return if there were an exception, and False if there were not. I think
> this was mentioned before. Is there a reason this is not acceptable?
> 

By which I presume the code could be:

generic
   with procedure Visit (Object : in out T);
procedure Refresh (Object : in out T; Dirty : in out Boolean) is
begin
   if Dirty then
      Visit (Object);
      Dirty := False;
   end if;
end Refresh;

Looks to be the simplest approach to me, though Bob Duff's
suggestion of a Cache type may be a better abstraction.

Robert Matthews




  reply	other threads:[~2010-03-16 19:25 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-12  9:13 Ensuring postconditions in the face of exceptions Ludovic Brenta
2010-03-12  9:24 ` Ludovic Brenta
2010-03-12  9:29 ` Niklas Holsti
2010-03-12 11:08   ` Ludovic Brenta
2010-03-12 14:00     ` Jeffrey R. Carter
2010-03-13  3:15       ` Randy Brukardt
2010-03-13 15:14         ` Robert A Duff
2010-03-16  3:13           ` Randy Brukardt
2010-03-16 15:18             ` Robert A Duff
2010-03-16 19:00               ` Adam Beneschan
2010-03-16 20:04                 ` Robert A Duff
2010-03-16 23:23               ` Randy Brukardt
2010-03-13 17:34         ` Jeffrey R. Carter
2010-03-13  7:54 ` Stephen Leake
     [not found] ` <ruqub2y84rqj.179q01lxzgatj$.dlg@40tude.net>
2010-03-13 19:33   ` Georg Bauhaus
2010-03-14 14:05 ` Alex Mentis
2010-03-14 14:21   ` Ludovic Brenta
2010-03-14 15:12     ` Alex Mentis
2010-03-15  9:14       ` Ludovic Brenta
2010-03-15 11:05         ` cjpsimon
2010-03-15 13:04           ` Ludovic Brenta
2010-03-15 14:16             ` J-P. Rosen
2010-03-15 19:14         ` Jeffrey R. Carter
2010-03-16 19:25           ` Robert Matthews [this message]
2010-03-14 15:38     ` Robert A Duff
2010-03-15  8:54       ` Ludovic Brenta
2010-03-15 16:44         ` Robert A Duff
2010-03-15 17:33           ` Ludovic Brenta
2010-03-15 18:36             ` Robert A Duff
2010-03-14 18:57     ` Jeffrey R. Carter
2010-03-15  8:56       ` Ludovic Brenta
2010-03-15 11:04 ` AdaMagica
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox