proposal: short => rewrite for function declarations
Petar
Petar
Mon Oct 12 12:59:11 UTC 2020
On Friday, 9 October 2020 at 14:44:25 UTC, Adam D. Ruppe wrote:
> After a brief chat yesterday, I slapped this together:
>
> https://github.com/dlang/dmd/pull/11833
>
> In short, in a function declaration, it rewrites `=> ...;` into
> `{ return ...; }`
>
> One benefit is shorter property accessors:
>
> private int _x = 34;
> @property x() => _x;
> @property x(int v) => _x = v;
>
> But it also works basically anywhere
>
> bool isNull() => this is null;
> auto identity(T)(T a) => a;
> @property y() in(true) => _x; // contracts still work too
>
> So it just extends the existing lambda shorthand to full
> declarations too.
>
> See more in the PR description and the test case there.
Thanks! Looking forward to beautifying our projects ;)
At work we already converted one of our projects that was written
in C# to use the new syntax about 2 years ago and overall it
makes reading and writing code with the new style much more
pleasant :)
For more info on this C# feature you can check:
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members
https://dotnettutorials.net/lesson/expression-bodied-members-csharp/
https://www.informit.com/articles/article.aspx?p=2414582
More information about the Digitalmars-d
mailing list