Optional braces

Jonathan M Davis jmdavisProg at gmx.com
Sun Aug 21 19:38:44 PDT 2011


On Sunday, August 21, 2011 20:36:55 bearophile wrote:
> Andrei Alexandrescu:
> > Yah, it's pretty neat, and very much in the spirit of D. I'd missed it.
> 
> Thank you Andrei. This problem is know as "Dangling else problem". When a
> bug receives a name, you know it's common enough.
> 
> This is one of the about one dozen of tiny/small breaking changes I'd like
> for D2. I'd like to speed up a little this very slow "presentation" I am
> doing of them, because it's taking a very long time (on the other hand this
> specific enhancement request did receive an answer).

Except that it's not a bug. It's an issue that crops up in grammars for 
programming languages. There is classic solution to the problem which D 
follows. So, there is no ambiguity, and there is no bug. It's very much by 
design.

 Bugs caused by mis-handling if statements related to dangling elses are 
_very_ rare in C-based languages. I really think that the only reason that 
you're running into this at all is because you've been translating python code 
to D without adding braces.

- Jonathan M Davis


More information about the Digitalmars-d mailing list