Notes IV

Don Clugston dac at nospam.com.au
Fri Jan 25 06:29:10 PST 2008


Oskar Linde wrote:
> 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.

I like that. That would catch almost all of the bugs, with no effect on good code.



More information about the Digitalmars-d mailing list