DMD 0.148 - scope guard
Regan Heath
regan at netwin.co.nz
Mon Feb 27 21:13:57 PST 2006
On Mon, 27 Feb 2006 21:05:33 -0800, S. Chancellor
<dnewsgr at mephit.kicks-ass.org> wrote:
> On 2006-02-25 18:06:36 -0800, "Walter Bright"
> <newshound at digitalmars.com> said:
>
>> Scope guards are a novel feature no other language has. They're based
>> on Andrei Alexandrescu's scope guard macros, which have led to
>> considerable interest in the idea. Check out the article
>> www.digitalmars.com/d/exception-safe.html
>
> The only thing I see that's amazingly useful about this is the
> on_scope_success. Having a block of code that is only executed when an
> exception is NOT thrown would be nice. However, the rest of this stuff
> seems like rocks under the water. Your example of the new programmer
> coming in reads like this to me: "The new programmer may not take the
> time to actually read the code he's modifying, so lets stick hidden
> stuff in there to take care of things he might have missed." Which
> doesn't seem very logical to me, as it may be just as important to
> modify those on success/on failure blocks and miss them.
>
> I'd say add another option to try..catch..finally paradigm.
You honestly don't think that this:
Transaction abc()
{
Foo f;
Bar b;
Def d;
f = dofoo();
on_scope_failure dofoo_unwind(f);
b = dobar();
on_scope_failure dobar_unwind(b);
d = dodef();
return Transaction(f, b, d);
}
is better than this:
Transaction abc()
{
Foo f;
Bar b;
Def d;
f = dofoo();
try {
b = dobar();
try {
d = dodef();
return Transaction(f, b, d);
}
catch(Object o) {
dobar_unwind(b);
throw o;
}
}
catch(Object o) {
dofoo_unwind(f);
throw o;
}
}
Regan
More information about the Digitalmars-d
mailing list