Discussion Thread: DIP 1043--Shortened Method Syntax--Community Review Round 1
Max Samukha
maxsamukha at gmail.com
Wed Feb 9 12:14:22 UTC 2022
On Wednesday, 9 February 2022 at 11:02:03 UTC, bauss wrote:
> Yes it does, but not if both cases aren't supported.
>
> And you shouldn't return the value from a setter, it should be
> void.
>
> Which looks better?
>
> ```
> int value() => _value;
> void value(int newValue) => _value = newValue;
Sorry, it doesn't look better to me. It looks as if the second
function has an incorrect return type. It would look better if it
was marked as a property setter and D handled property setters
specially.
> ```
>
> Or
>
> ```
> int value() => _value;
> void value(int newValue) { _value = newValue; }
> ```
>
> The first case definitely looks better IMHO.
>
> And yeah as you said void could just be int, but it shouldn't.
> The setter should be void.
>
> It is almost universally accepted that setters should __never__
> return anything and there's only one case where you might
> return from a setter and that is in fluid programming where you
> return the parent object to allow chaining.
>
> So it's irrelevant that it works as a work-around.
Are we discussing this proposal, which is about unifying named
and anonymous function syntax? Changing the way D handles
property setters is a separate issue.
More information about the Digitalmars-d
mailing list