Optional braces
kennytm
kennytm at gmail.com
Wed Aug 24 01:09:38 PDT 2011
Walter Bright <newshound2 at digitalmars.com> 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.
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");
More information about the Digitalmars-d
mailing list