February 27, 2006
> How about
> on_scope_exit -> scope exit
> on_scope_success -> scope success
> on_scope_failure -> scope failure
> ?
>
> on_prefixed_underscore_separated_keywords just look obtrusive in D code.

I don't like the _ either (mostly because D doesn't have any other _s in the language, I know of), but I think reserving "exit", "failure" and "success" would be even worse. I'd rather have the _s.

L.


February 27, 2006
"Walter Bright" <newshound@digitalmars.com> wrote in message news:dtr2fg$2vqr$4@digitaldaemon.com...
> 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

Note GCC has pretty much the same thing with the "cleanup" attribute extension on variables: http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Variable-Attributes.html


February 27, 2006
Cris wrote:

> Now you have just to persuade Walter Bright or to write your own compiler/language :)

I only hope Walter will take a look how much possibilities he have. I just don't like operators_with_underscore and everybody seems to agree that they don't fit well with beauty of D.
February 27, 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
> 
> 
Sweet!
There is probably room to improve the syntax a bit more (although I too don't yet see how), but it is already a fine feature.

-- 
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
February 27, 2006
Walter Bright wrote:
> "Derek Parnell" <derek@psych.ward> wrote in message news:op.s5j942tp6b8z09@ginger.vic.bigpond.net.au...
>> Does 'scope' mean any type scope, and not just function scope? For example, can it include module scope? ... if/while/for/foreach scope? ... block scope?
> 
> Yes.
> 

On module scope? No, it doesn't actually work on module scope, right? Wouldn't make sense, as a module scope is a declaration scope, and not a instruction scope/block.

-- 
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
February 27, 2006
On Sat, 25 Feb 2006 21:06:36 -0500, Walter Bright <newshound@digitalmars.com> 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
>

This format looks good to me:

scope(exit)  foo();
scope(success)  bar();
scope(failure)  baz();

similar to extern(name), pragma(name), etc, requires one `scope` keyword, name in () doesn't need to be a keyword but is still treated special, and doesn't look bad.
February 27, 2006
Chris Miller wrote:

> On Sat, 25 Feb 2006 21:06:36 -0500, Walter Bright <newshound@digitalmars.com> 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
>>
> 
> This format looks good to me:
> 
> scope(exit)  foo();
> scope(success)  bar();
> scope(failure)  baz();
> 
> similar to extern(name), pragma(name), etc, requires one `scope` keyword,
> name in () doesn't need to be a keyword but is still treated special, and
> doesn't look bad.

Me votes for this too.
February 27, 2006
On Tue, 28 Feb 2006 04:40:56 +1100, Chris Miller <chris@dprogramming.com> wrote:

> On Sat, 25 Feb 2006 21:06:36 -0500, Walter Bright <newshound@digitalmars.com> 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
>>
>
> This format looks good to me:
>
> scope(exit)  foo();
> scope(success)  bar();
> scope(failure)  baz();
>
> similar to extern(name), pragma(name), etc, requires one `scope` keyword, name in () doesn't need to be a keyword but is still treated special, and doesn't look bad.

Nice and consistent.

-- 
Derek Parnell
Melbourne, Australia
February 27, 2006
I am with Charles here...

I don't understand why
on_scope_failure & co. are significantly better than
try catch finally?

What is wrong with them?

Semantically try-catch-finally are well known and
widely recognizable constructions.

BTW: Am I right in my assumption that
proposed on_scope_exit / on_scope_success / on_scope_failure
is a direct equivalent of the following:

try
{
   [scope code]
   my_on_scope_success().
}
catch(...)
{
   my_on_scope_failure().
}
finally {
  my_on_scope_exit().
}

If yes then again what it wrong with them in principle?


Andrew.
http://terrainformatica.com











February 27, 2006
"Bruno Medeiros" <daiphoenixNO@SPAMlycos.com> wrote in message news:dtvcoj$225e$1@digitaldaemon.com...
> Walter Bright wrote:
>> "Derek Parnell" <derek@psych.ward> wrote in message news:op.s5j942tp6b8z09@ginger.vic.bigpond.net.au...
>>> Does 'scope' mean any type scope, and not just function scope? For example, can it include module scope? ... if/while/for/foreach scope? ... block scope?
>>
>> Yes.
>>
>
> On module scope? No, it doesn't actually work on module scope, right? Wouldn't make sense, as a module scope is a declaration scope, and not a instruction scope/block.

That's right. You can't have statements in module scope, so there's no way to apply it to module scope. Or class scope. Or any other place where statements are not allowed.