DMD 0.148 - scope guard

Dawid Ciężarkiewicz dawid.ciezarkiewicz at gmail.com
Sun Feb 26 04:15:52 PST 2006


Walter Bright wrote:

> 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

Concept is really promising. Syntax ... well ... :D

I try to come with some other syntaxs.

ORYGINAL:

void LongFunction()
{
    State save = UIElement.GetState();
    on_scope_success UIElement.SetState(save);
    on_scope_failure UIElement.SetState(Failed(save));
    ...lots of code...
}

Why not:


VERSION A:
void LongFunction()
{
    State save = UIElement.GetState();
    on (success) {
         UIElement.SetState(save)
    }
    on (failure) {
        UIElement.SetState(Failed(save))
    }
    ...lots of code...
}

(not that success and failure could be recognized only as "on" keyword's
argument.)


VERSION B:
void LongFunction()
{
    State save = UIElement.GetState();
    scope (success) {
        UIElement.SetState(save);
    }
    scope (failure) {
        UIElement.SetState(Failed(save));
    }
    ...lots of code...
}

VERSION C:
void LongFunction()
{
    State save = UIElement.GetState();
    scope_success UIElement.SetState(save);
    scope_failure UIElement.SetState(Failed(save));
    ...lots of code...
}


What do you think? Maybe later we'll come with better ideas.



More information about the Digitalmars-d mailing list