Optional braces

Jacob Carlborg doob at me.com
Thu Aug 18 23:50:28 PDT 2011


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

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list