why scope(success)?

Regan Heath regan at netwin.co.nz
Tue May 9 17:16:32 PDT 2006


On Tue, 9 May 2006 15:17:38 -0400, Ben Hinkle <bhinkle at mathworks.com>  
wrote:

> I hope this doesn't come of as a flame, but I'm wondering if anyone is  
> using
> scope(success) and why. I can't find any reason for it.
>
> Some background: I've slowed my D work to focus on some C experimental
> features I'm calling Cx: http://www.tinycx.org and currently I'm
> implementing the error handling using reserved labels "error:" and
> "finally:". The error label is roughly like scope(failure) and the  
> finally
> label is roughly like scope(exit). There's no try-catch-finally. I don't
> plan on adding anything like scope(success) because I couldn't think of  
> why
> anyone would want to use it. Why not just put the code at the end of the
> scope like normal code-flow? I suppose one could code the entire scope in
> reverse just for kicks:
> void main() {
>   scope(success) printf("world\n");
>   scope(success) printf("hello ");
> }

Maybe... self documenting functions, listing all return values at the top?

int foobar( ..etc.. )
{
   scope(success) return 1;
   scope(failure) return 0;

}

As someone else mentioned, commiting changes to a database, perhaps  
several, some of which are optional depending on program flow eg.

int foobar( ..etc..)
{
   if (a) {
     ..make changes to a..
     scope(success) db.commit(a);
   }

   if (b) {
     ..make changes to b..
     scope(success) db.commit(b);
   }

   ..make changes to c..
   db.commit(c); //no scope.. required here
   return 1;
}

Regan



More information about the Digitalmars-d mailing list