proposal: short => rewrite for function declarations

Fred fred at gmail.com
Sat Oct 10 14:25:31 UTC 2020


On Saturday, 10 October 2020 at 13:05:48 UTC, Mike Parker wrote:
> On Saturday, 10 October 2020 at 12:30:24 UTC, Imperatorn wrote:
>
>>>
>>> @property x() => _x;
>>>
>>> vs
>>>
>>> @property x() { return -x; }
>>>
>>> cause the important thing to me is that my code is simple, 
>>> readable, expressive, i dont care about saving 7 chars on a 
>>> one liner.
>>
>> What do you mean. It removes stuff. I'd say Adam's proposal is 
>> more readable.
>
> Not to me. Taking away the braces and the return statement 
> turns it into a foreign language.

It's literally how lambda's are defined.

auto x = () => _x; // no return statement, no braces
auto x = () { return _x; }; // exactly the same


More information about the Digitalmars-d mailing list