Optional braces
Timon Gehr
timon.gehr at gmx.ch
Tue Aug 23 14:31:55 PDT 2011
On 08/23/2011 10:46 PM, Walter Bright wrote:
> On 8/19/2011 8:12 AM, Andrei Alexandrescu wrote:
>> One thing I'd subjectively like is to require braces on both branches
>> of if/else
>> if at least one has braces.
>
> It's rather simple to just disallow the form:
>
> if (a) if (b) statement
> ^ error: use if(a&&b) or if(a){if(b)statement}
>
> and not even pay attention if there's a dangling else or not. I've
> always viewed things like:
>
> if (a)
> if (b)
> ...
> ...
>
> with suspicion, anyway, dangling else or not.
I agree, but imho
if (a)
if (b) ...
else ...
else ...
would not /have/ to be disallowed, because it is unambiguous for a
context-free grammar parser, and therefore for humans. (but I'd not cry
if it was)
More information about the Digitalmars-d
mailing list