Notes IV

Oskar Linde oskar.lindeREM at OVEgmail.com
Fri Jan 25 05:37:38 PST 2008


bearophile wrote:

> 18b)
> Here indentation doesn't follow the program meaning:
> if (x == 0)
>     if (y == 0)
>         foo();
> else
>     z = x + y;
> 

I've only been bitten by this maybe two times ever, but one was quite 
recent and took a fair amount of time to track down. (I went as far as 
reading the compiler assembler output before realizing what was wrong... 
and feeling quite stupid.)

I think it went something like starting with

if (a)
     b();
else
     c();

and later mindlessly changing several b(); into if(d) b();

> But Making D *require* {} after for, while, if/else, ecc looks like a "draconian" way to avoid that kind of bugs.

I agree. A working compromise would be to disallow only "ambiguous" else 
clauses, forcing one to add {} in those cases only.

-- 
Oskar



More information about the Digitalmars-d mailing list