Optional braces

Mehrdad wfunction at hotmail.com
Fri Aug 19 20:24:58 PDT 2011


On 8/19/2011 8:29 AM, Timon Gehr wrote:
> On 08/19/2011 05:12 PM, 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
>>
>
> if(condition){
>     ...;
> }();else ...;
>
> if(condition) ...;
> else{
>     ...
> }();
>
>
> :o)
Holy cow, that's a really scary way of doing an "if"...


More information about the Digitalmars-d mailing list