Optional braces

Jacob Carlborg doob at me.com
Fri Aug 19 10:09:25 PDT 2011


On 2011-08-19 17:12, Andrei Alexandrescu wrote:
> On 8/19/11 1:50 AM, Jacob Carlborg wrote:
>> This might sound like a crazy idea. I don't expect everyone to drop what
>> they're doing and start to implement this, it's just an idea.
>>
>> In Java (C, C++ and others) braces are optional for statements like if,
>> while, for and so on, containing only one expression. In D this is true
>> as well, but compared with Java, D also allow try, catch and finally
>> statements to have optional braces.
>>
>> What about extending this to allow optional braces everywhere, where the
>> braces contain a single expression? I'm thinking this will be most
>> useful for functions/methods, templates and delegates. Specially for
>> methods acting as properties that just forwards a value.
>>
>> Examples:
>>
>> class Foo
>> {
>> private int a_;
>> int a () return a_;
>> int a (int a) return a_ = a;
>> }
>>
>> template Bar (T) alias T FooBar;
>>
>> auto foo = delegate () return 3;
>> auto bar = return 3; // don't if this would be possible
>
> One thing I'd subjectively like is to require braces on both branches of
> if/else if at least one has braces.
>
> Andrei
>

Why is that?

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list