Discussion Thread: DIP 1043--Shortened Method Syntax--Final Review

Steven Schveighoffer schveiguy at gmail.com
Wed Jun 15 13:49:04 UTC 2022


On 6/15/22 5:35 AM, bauss wrote:
> On Wednesday, 15 June 2022 at 09:21:12 UTC, Mike Parker wrote:
>> This is the discussion thread for the Final Review of DIP 1043, 
>> "Shortened Method Syntax":
>>
>> https://github.com/dlang/DIPs/blob/2c2f6c33f5761236266a96bd268c62a06323a5e8/DIPs/DIP1043.md 
>>
>>
>> The review period will end at 11:59 PM ET on June 29, or when I make a 
>> post declaring it complete. Discussion in this thread may continue 
>> beyond that point.
>>
>> Here in the discussion thread, you are free to discuss anything and 
>> everything related to the DIP. Express your support or opposition, 
>> debate alternatives, argue the merits, etc.
>>
>> However, if you have any specific feedback on how to improve the 
>> proposal itself, then please post it in the feedback thread. The 
>> feedback thread will be the source for the review summary I write at 
>> the end of this review round. I will post a link to that thread 
>> immediately following this post. Just be sure to read and understand 
>> the Reviewer Guidelines before posting there:
>>
>> https://github.com/dlang/DIPs/blob/master/docs/guidelines-reviewers.md
>>
>> And my blog post on the difference between the Discussion and Feedback 
>> threads:
>>
>> https://dlang.org/blog/2020/01/26/dip-reviews-discussion-vs-feedback/
>>
>> Please stay on topic here. I will delete posts that are completely 
>> off-topic.
> 
> I'm still under the belief that it shouldn't just be `AssignExpression`, 
> because you should be able to use it to call another function that has 
> no return type.
> 
> Ex.
> 
> ```d
> void a(int x, int y) { ... }
> 
> void b(int x) => a(x, 100);
> ```
> 
> As the DIP uses C# as a prime example of it, because the above will work 
> in C#.
> 
> It's very useful for things like this:
> 
> ```d
> @property int x() => _x;
> @property void x(int value) => _x = value;
> ```
> 
> C# equivalent:
> 
> ```d
> int X { get => _x;  set => _x = value; }
> ```
> 
> I might not understand something from the DIP, but I don't think it's 
> clear whether that is supported or not and `AssignExpression` tells me 
> that it's not, but maybe I don't understand what `AssignExpression` 
> exactly entails.

AssignExpression is correct.

in the grammar, a [return 
statement](https://dlang.org/spec/statement.html#return-statement) is 
`return Expression`.

An [Expression](https://dlang.org/spec/expression.html#Expression) is 
`CommaExpression`, which is:

```
AssignExpression
Expression , AssignExpression
```

(https://dlang.org/spec/expression.html#CommaExpression)

So unless you need comma expressions (which are technically illegal as a 
return expression), AssignExpression is equivalent. This basically is 
trimming the "fat" of the comma expression from where it's already illegal.

Note that this works today:

```d
void foo() {}
void bar() { return foo(); }
```

So I wouldn't expect shortened methods to work any different. Indeed 
with the preview switch they do:

```d
void baz() => foo(); // compiles
```

-Steve


More information about the Digitalmars-d mailing list