Jump to page: 1 26  
Page
Thread overview
Discussion Thread: DIP 1043--Shortened Method Syntax--Community Review Round 1
Feb 04, 2022
Mike Parker
Feb 04, 2022
Mike Parker
Feb 04, 2022
Elronnd
Feb 04, 2022
max haughton
Feb 04, 2022
Paul Backus
Feb 04, 2022
Tejas
Feb 04, 2022
Timon Gehr
Feb 04, 2022
Paul Backus
Feb 08, 2022
Timon Gehr
Feb 04, 2022
Basile B.
Feb 04, 2022
Timon Gehr
Feb 05, 2022
Basile B.
Feb 04, 2022
max haughton
Feb 04, 2022
Rumbu
Feb 04, 2022
max haughton
Feb 05, 2022
bauss
Feb 05, 2022
Basile B.
Feb 05, 2022
Doigt
Feb 05, 2022
Paul Backus
Feb 05, 2022
Doigt
Feb 06, 2022
bauss
Feb 08, 2022
Max Samukha
Feb 08, 2022
Doigt
Feb 08, 2022
Adam D Ruppe
Feb 09, 2022
bauss
Feb 09, 2022
Max Samukha
Feb 09, 2022
bauss
Feb 09, 2022
Max Samukha
Feb 09, 2022
bauss
Feb 09, 2022
Max Samukha
Feb 09, 2022
Adam D Ruppe
Feb 09, 2022
Adam D Ruppe
Feb 09, 2022
bauss
Feb 09, 2022
Kagamin
Feb 05, 2022
forkit
Feb 05, 2022
Paul Backus
Feb 05, 2022
rikki cattermole
Feb 05, 2022
forkit
Feb 05, 2022
Guillaume Piolat
Feb 05, 2022
forkit
Feb 05, 2022
IGotD-
Feb 06, 2022
Tejas
Feb 09, 2022
Kagamin
Feb 09, 2022
Kagamin
Feb 09, 2022
Timon Gehr
Feb 09, 2022
bauss
February 04, 2022

Discussion Thread

This is the discussion thread for the first round of Community
Review of DIP 1043, "Shortened Method Syntax":

https://github.com/dlang/DIPs/blob/5a3b437f2b6be8fb23e855fc0da20f19f68edac8/DIPs/DIP1043.md

The review period will end at 11:59 PM ET on February 18, 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 that I
will 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.

February 04, 2022

On Friday, 4 February 2022 at 10:53:45 UTC, Mike Parker wrote:

>

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 that I
will write at the end of this review round. I will post a link to that thread immediately following this post.

The Feedback Thread is here:

https://forum.dlang.org/post/picueoqamrouueyntjmk@forum.dlang.org

February 04, 2022
It would be nice to permit something like this:

struct Foo {
    this(int x, string y) { ... }
    this(string y) => this(0, y);
}

Currently this fails because constructors are not allowed to return anything.  But that should not be part of this DIP, probably.
February 04, 2022
On Friday, 4 February 2022 at 11:21:48 UTC, Elronnd wrote:
> It would be nice to permit something like this:
>
> struct Foo {
>     this(int x, string y) { ... }
>     this(string y) => this(0, y);
> }
>
> Currently this fails because constructors are not allowed to return anything.  But that should not be part of this DIP, probably.

The implementation as done by Adam is done in the parser but if I move it down the stack a bit this is probably doable.
February 04, 2022

Why AssignExpression and not Expression?

Expression will allow shortened syntax also for constructors, destructors and void functions.

February 04, 2022

On Friday, 4 February 2022 at 12:48:20 UTC, Rumbu wrote:

>

Why AssignExpression and not Expression?

Expression will allow shortened syntax also for constructors, destructors and void functions.

That's what the current implementation does.

Also unless you mean allowing comma expressions, AssignExpression is the highest level in the grammar available.

February 04, 2022
On Friday, 4 February 2022 at 12:40:32 UTC, max haughton wrote:
> On Friday, 4 February 2022 at 11:21:48 UTC, Elronnd wrote:
>> It would be nice to permit something like this:
>>
>> struct Foo {
>>     this(int x, string y) { ... }
>>     this(string y) => this(0, y);
>> }
>>
>> Currently this fails because constructors are not allowed to return anything.  But that should not be part of this DIP, probably.
>
> The implementation as done by Adam is done in the parser but if I move it down the stack a bit this is probably doable.

Please don't. Having `=> expr` be simple syntax sugar for `{ return expr; }` is consistent and easy to understand. We don't need to add special cases just to save a *single character*:

    this(string y) => this(0, y);
    this(string y) { this(0, y); }
February 04, 2022

On Friday, 4 February 2022 at 14:46:39 UTC, Paul Backus wrote:

>

On Friday, 4 February 2022 at 12:40:32 UTC, max haughton wrote:

>

On Friday, 4 February 2022 at 11:21:48 UTC, Elronnd wrote:

>

It would be nice to permit something like this:

struct Foo {
this(int x, string y) { ... }
this(string y) => this(0, y);
}

Currently this fails because constructors are not allowed to return anything. But that should not be part of this DIP, probably.

The implementation as done by Adam is done in the parser but if I move it down the stack a bit this is probably doable.

Please don't. Having => expr be simple syntax sugar for { return expr; } is consistent and easy to understand. We don't need to add special cases just to save a single character:

this(string y) => this(0, y);
this(string y) { this(0, y); }

Actually, the following compiles:

void funcc()
{
}

void func()
{
    return funcc();
}
void main()
{
    func();

}

So maybe the fact that this(string y) => this(0, y); doesn't compile is a compiler bug? Constructors return void after all, no?

February 04, 2022
On Friday, 4 February 2022 at 14:46:39 UTC, Paul Backus wrote:
> On Friday, 4 February 2022 at 12:40:32 UTC, max haughton wrote:
>> On Friday, 4 February 2022 at 11:21:48 UTC, Elronnd wrote:
>>> [...]
>>
>> The implementation as done by Adam is done in the parser but if I move it down the stack a bit this is probably doable.
>
> Please don't. Having `=> expr` be simple syntax sugar for `{ return expr; }` is consistent and easy to understand. We don't need to add special cases just to save a *single character*:
>
>     this(string y) => this(0, y);
>     this(string y) { this(0, y); }

I am going to move it down the stack for implementation reasons (syntax reproduction and error messages) anyway but point taken.
February 04, 2022
On 04.02.22 18:18, Tejas wrote:
> On Friday, 4 February 2022 at 14:46:39 UTC, Paul Backus wrote:
>> On Friday, 4 February 2022 at 12:40:32 UTC, max haughton wrote:
>>> On Friday, 4 February 2022 at 11:21:48 UTC, Elronnd wrote:
>>>> It would be nice to permit something like this:
>>>>
>>>> struct Foo {
>>>>     this(int x, string y) { ... }
>>>>     this(string y) => this(0, y);
>>>> }
>>>>
>>>> Currently this fails because constructors are not allowed to return anything.  But that should not be part of this DIP, probably.
>>>
>>> The implementation as done by Adam is done in the parser but if I move it down the stack a bit this is probably doable.
>>
>> Please don't. Having `=> expr` be simple syntax sugar for `{ return expr; }` is consistent and easy to understand.

Yes, no need to change the implementation of this feature, just fix semantic analysis of constructors.

>> We don't need to add special cases just to save a *single character*:
>> ...

Sure, but actually, the fact that the example code does not already work with the current implementation of the feature is the special case. There is even less need to add special cases just so people have to waste an additional character. (Plus some white space, by the way, at least outside of personal projects. There may be strict style guidelines.)

>>     this(string y) => this(0, y);
>>     this(string y) { this(0, y); }
> ...

If you have to violate common style guidelines in order to support a claim that the status quo is not so much worse, then probably the new syntax is actually significantly better. (Razvan did the same in the feedback thread, I don't get why people are doing this. Would this really fly, e.g., in Phobos?)

> Actually, the following compiles:
> ```d
> void funcc()
> {
> }
> 
> void func()
> {
>      return funcc();
> }
> void main()
> {
>      func();
> 
> }
> ```
> So maybe the fact that `this(string y) => this(0, y);` doesn't compile is a compiler bug? Constructors return `void` after all, no?

I think so, or at least it's an undesirable special case:

```d
void foo(){ return; }
struct S{
    this(int x){ return; } // ok, can return void
    this(int x,int y){ return foo(); } // error
}
```

"Error: cannot return expression from constructor"
« First   ‹ Prev
1 2 3 4 5 6