Discussion Thread: DIP 1043--Shortened Method Syntax--Community Review Round 1

Max Samukha maxsamukha at gmail.com
Wed Feb 9 10:34:57 UTC 2022


On Wednesday, 9 February 2022 at 07:54:20 UTC, bauss wrote:
> On Tuesday, 8 February 2022 at 17:11:19 UTC, Adam D Ruppe wrote:
>> On Tuesday, 8 February 2022 at 17:03:25 UTC, Doigt wrote:
>>> you'll see exactly that they also have a case for lambda 
>>> expressions with no return values
>>
>> Which example is that? Do they assign it to a value of a 
>> different type?
>>
>
> I think the whole argument is that this will work in C#:
>
> ```d
> int Value
> {
>   get => _value;
>   set => _value = value; // This is okay
> }
> ```
>
> But it won't work in D according to this DIP:
>
> ```d
> int value() => _value;
> void value(int newValue) => _value = newValue; // This will not 
> work
> ```
>

I don't understand why the fact that C# has a special case for 
setters is relevant. Even though the setter in C# has 'void' 
return value, the actual return type of the assignment is still 
int. Consider:

var y = x.Value = 42;

which the compiler rewrites to something like:

x.set_Value(42);
var y = x.get_Value();

In D, you just return the new value from the setter:

int value(int newValue) => _value = newValue;

> So instead everything becomes inconsistent like:
>
> ```d
> int value() => _value;
> void value(int newValue) { _value = newValue; } // This is ok 
> obv.
> ```
>
> However, now the code looks inconsistent and not intuitive at 
> all.

I disagree. The proposed feature makes D overall more consistent.



More information about the Digitalmars-d mailing list