proposal: short => rewrite for function declarations

Patrick Schluter Patrick.Schluter at bbox.fr
Sat Oct 10 14:25:02 UTC 2020


On Saturday, 10 October 2020 at 13:55:13 UTC, Imperatorn wrote:
> 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.
>
> Might be a bit of a stretch to say it becomes a "foreign 
> language" just because you change one thing... But, I do agree 
> that in general you should be very restrictive about adding 
> things. A new feature always seems so nice and shiny in the 
> beginning, before you have analysed its potential side effects.

It's a question of point of view.
This is not adding a new feature, it's removing a restriction. 
The lambdas (i.e. unnamed functions) have 2 possible syntaxes. 
Named functions have only 1. This is inconsistent. Removing the 
second syntax from lambdas is not possible (unending breakage) so 
it is more logic to remove the syntax restriction from named 
functions. As shown it is a very simple change and it removes an 
artificial restriction.
It is clear that dubious languages and syntax additions are to be 
avoided but this ain't any of it.


More information about the Digitalmars-d mailing list