Escape analysis

Christopher Wright dhasenan at gmail.com
Sat Nov 1 10:52:35 PDT 2008


Walter Bright wrote:
> void bar(noscope int* p);    // p escapes
> void bar(scope int* p);      // p does not escape
> void bar(int* p);            // what should be the default?
> 
> What should be the default? The functional programmer would probably 
> choose scope as the default, and the OOP programmer noscope.
> 
> (The issue with delegates is we need the dynamic closure only if the 
> delegate 'escapes'.)

I appreciate OOP. I also appreciate it when it takes no significant 
effort to write safe code. I also appreciate it when I don't have to 
convince the compiler that what I'm doing is safe when I know it's safe.

In the case of pointers, I don't use them, most of the time. (I'm 
working on a variable-key-length cache-oblivious lookahead array right 
now, and that requires pointers for efficiency, but this is probably the 
first time I've used pointers in D.)

In the case of delegates, I use them. I've been confused and upset by 
the lack of closures in D1. I think a lot of new programmers will expect 
closures and get confused by having two different ways of declaring them.

For my code, I won't mind using whatever new syntax for closures, even 
if it's slightly verbose. For new programmers, I'd recommend using 
closures by default, since they're safer. Once they're more comfortable 
with the language, you can introduce the idea of allocating delegate 
context on the stack as an occasionally unsafe optimization.



More information about the Digitalmars-d mailing list