Optional braces

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Aug 23 15:32:36 PDT 2011


On 8/23/11 2:31 PM, Timon Gehr wrote:
> 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)

Yah, disallowing complete and nested if/else pairs would be an annoyance 
(I'm not sure how big). Otherwise, Walter's idea sounds good to me. 
Walter, would you be okay with accepting if-if-else-else (at any depth) 
as a correct case and otherwise disable nested incomplete ifs?

Andrei


More information about the Digitalmars-d mailing list