Optional braces

Timon Gehr timon.gehr at gmx.ch
Wed Aug 24 09:53:11 PDT 2011


On 08/24/2011 06:22 PM, Walter Bright wrote:
> On 8/24/2011 1:09 AM, kennytm wrote:
>> Not sure if it's a big enough problem, but what about dangling else of
>> this
>> form?
>>
>> if (a.length> 0)
>> foreach (i, ref e; a)
>> if (i> 0)
>> e += a[i-1];
>> else // oops
>> throw new Exception("empty array");
>
> That wouldn't be complained about with what I suggested. This isn't the
> dangling else problem, though, it's just bad indenting.

I'd say this is actually the dangling else problem. (When it occurs, it 
is always just bad indenting) Without the tie-breaker, the code snippet 
would be ambiguous. That is a case that should be catched.


More information about the Digitalmars-d mailing list