Should scope(exit) be valid outside of a scope?

Simen kjaeraas simen.kjaras at gmail.com
Wed May 12 07:41:32 PDT 2010


Graham Fawcett <fawcett at uwindsor.ca> wrote:

> On Tue, 11 May 2010 22:18:29 +0200, Don wrote:
>
>> void foo(bool x)
>> {
>>     if (x)
>>        scope(exit) writeln("exiting");
>>     writeln("body");
>> }
>
> Doesn't this do what you want, without changing the language?
>
> void foo(bool x) {
>     scope(exit) {	
>       if (x) writeln("exiting");
>     }
>     // ...
> }

Absolutely. but it is currently possible to write the code Don
wrote, have it compile, and feel that this is completely
pointless. Which it is.

That is, if scope(whatever) is the only thing inside a scope,
something is wrong. D already warns us of other stupid things
we do, and this is a prime candidate.

-- 
Simen


More information about the Digitalmars-d mailing list