Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
June 27, 2018 Preferred Alias Declaration Style | ||||
---|---|---|---|---|
| ||||
Most of the documentation at https://dlang.org/spec/declaration.html#alias uses examples of the form: `alias aliasName = other;`, where `aliasName` becomes the new name to reference `other`. Alternatively, one may write `alias other aliasName;`. My understanding is that the syntax with `=` is the preferred one stylistically. However, when it comes to `alias this` declarations, the only syntax supported is `alias other this;`, and one cannot write `alias this = other;`. Does this mean that the `alias other aliasName;` syntax is preferred, or does it simply mean that this is a low priority issue that hasn't been addressed yet? |
June 27, 2018 Re: Preferred Alias Declaration Style | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vijay Nayar | On Wednesday, 27 June 2018 at 10:22:38 UTC, Vijay Nayar wrote:
> Most of the documentation at https://dlang.org/spec/declaration.html#alias uses examples of the form: `alias aliasName = other;`, where `aliasName` becomes the new name to reference `other`. Alternatively, one may write `alias other aliasName;`. My understanding is that the syntax with `=` is the preferred one stylistically.
>
> However, when it comes to `alias this` declarations, the only syntax supported is `alias other this;`, and one cannot write `alias this = other;`.
>
> Does this mean that the `alias other aliasName;` syntax is preferred, or does it simply mean that this is a low priority issue that hasn't been addressed yet?
`alias Alias = SomeType;` is preferred. It is the new style, and is more clear on what is the alias and what is the new type, especially when complex types come into play. For `alias this` though, there is only one syntax, `alias other this;`, since it does something conceptually different from regular aliases.
|
June 27, 2018 Re: Preferred Alias Declaration Style | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uknown | On Wednesday, 27 June 2018 at 12:25:26 UTC, Uknown wrote:
> On Wednesday, 27 June 2018 at 10:22:38 UTC, Vijay Nayar wrote:
>> Most of the documentation at https://dlang.org/spec/declaration.html#alias uses examples of the form: `alias aliasName = other;`, where `aliasName` becomes the new name to reference `other`. Alternatively, one may write `alias other aliasName;`. My understanding is that the syntax with `=` is the preferred one stylistically.
>>
>> However, when it comes to `alias this` declarations, the only syntax supported is `alias other this;`, and one cannot write `alias this = other;`.
>>
>> Does this mean that the `alias other aliasName;` syntax is preferred, or does it simply mean that this is a low priority issue that hasn't been addressed yet?
>
> `alias Alias = SomeType;` is preferred. It is the new style, and is more clear on what is the alias and what is the new type, especially when complex types come into play. For `alias this` though, there is only one syntax, `alias other this;`, since it does something conceptually different from regular aliases.
aliasing a function type only works with the old syntax too:
alias void proto_identifier();
Very unfriendly syntax. Impossible to express with AliasDeclarationY (aka "the new alias syntax").
|
June 27, 2018 Re: Preferred Alias Declaration Style | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Wednesday, 27 June 2018 at 14:01:06 UTC, Basile B. wrote:
> On Wednesday, 27 June 2018 at 12:25:26 UTC, Uknown wrote:
>> On Wednesday, 27 June 2018 at 10:22:38 UTC, Vijay Nayar wrote:
>>> [...]
>
> aliasing a function type only works with the old syntax too:
>
> alias void proto_identifier();
>
> Very unfriendly syntax. Impossible to express with AliasDeclarationY (aka "the new alias syntax").
You can use this syntax for functions :
`alias proto_identifier = void function();`
|
June 27, 2018 Re: Preferred Alias Declaration Style | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uknown | On Wednesday, 27 June 2018 at 14:23:25 UTC, Uknown wrote: > On Wednesday, 27 June 2018 at 14:01:06 UTC, Basile B. wrote: >> On Wednesday, 27 June 2018 at 12:25:26 UTC, Uknown wrote: >>> On Wednesday, 27 June 2018 at 10:22:38 UTC, Vijay Nayar wrote: >>>> [...] >> >> aliasing a function type only works with the old syntax too: >> >> alias void proto_identifier(); >> >> Very unfriendly syntax. Impossible to express with AliasDeclarationY (aka "the new alias syntax"). > > You can use this syntax for functions : > > `alias proto_identifier = void function();` Nah it's not the same thing ;) ---- void main() { alias void proto_identifier_old(); alias proto_identifier_new = void function(); assert(!is(proto_identifier_old == proto_identifier_new)); // passes } ---- - proto_identifier_new is a function type (stuff) - proto_identifier_new is a function **pointer** type (e.g &stuff) Actually my answer was more informative because i reported this limitation years ago, see https://issues.dlang.org/show_bug.cgi?id=16020. |
June 27, 2018 Re: Preferred Alias Declaration Style | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Wednesday, 27 June 2018 at 14:29:18 UTC, Basile B. wrote:
> On Wednesday, 27 June 2018 at 14:23:25 UTC, Uknown wrote:
>> On Wednesday, 27 June 2018 at 14:01:06 UTC, Basile B. wrote:
>>> On Wednesday, 27 June 2018 at 12:25:26 UTC, Uknown wrote:
>>>> On Wednesday, 27 June 2018 at 10:22:38 UTC, Vijay Nayar wrote:
>>>>> [...]
> Nah it's not the same thing ;)
>
> ----
> void main()
> {
> alias void proto_identifier_old();
> alias proto_identifier_new = void function();
> assert(!is(proto_identifier_old == proto_identifier_new)); // passes
> }
> ----
>
> - proto_identifier_new is a function type (stuff)
> - proto_identifier_new is a function **pointer** type (e.g &stuff)
>
> Actually my answer was more informative because i reported this limitation years ago, see https://issues.dlang.org/show_bug.cgi?id=16020.
Didn't know that, I assumed that the old style also declared a function pointer
|
June 27, 2018 Re: Preferred Alias Declaration Style | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Wednesday, 27 June 2018 at 14:29:18 UTC, Basile B. wrote:
> On Wednesday, 27 June 2018 at 14:23:25 UTC, Uknown wrote:
>> On Wednesday, 27 June 2018 at 14:01:06 UTC, Basile B. wrote:
>>> [...]
>>
>> You can use this syntax for functions :
>>
>> `alias proto_identifier = void function();`
>
> Nah it's not the same thing ;)
>
> ----
> void main()
> {
> alias void proto_identifier_old();
> alias proto_identifier_new = void function();
> assert(!is(proto_identifier_old == proto_identifier_new)); // passes
> }
> ----
>
> - proto_identifier_new is a function type (stuff)
> - proto_identifier_new is a function **pointer** type (e.g &stuff)
>
> Actually my answer was more informative because i reported this limitation years ago, see https://issues.dlang.org/show_bug.cgi?id=16020.
Ah s**t i meant
- proto_identifier_old is a function type (stuff)
- proto_identifier_new is a function **pointer** type
|
June 27, 2018 Re: Preferred Alias Declaration Style | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vijay Nayar | On 6/27/18 6:22 AM, Vijay Nayar wrote:
> Does this mean that the `alias other aliasName;` syntax is preferred, or does it simply mean that this is a low priority issue that hasn't been addressed yet?
IIRC, there was an ambiguity for using the new syntax for alias this. I don't remember the thread where it was discussed, but you are not the first to bring it up.
-Steve
|
June 27, 2018 Re: Preferred Alias Declaration Style | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Wednesday, 27 June 2018 at 15:27:09 UTC, Steven Schveighoffer wrote: > On 6/27/18 6:22 AM, Vijay Nayar wrote: >> Does this mean that the `alias other aliasName;` syntax is preferred, or does it simply mean that this is a low priority issue that hasn't been addressed yet? > > IIRC, there was an ambiguity for using the new syntax for alias this. I don't remember the thread where it was discussed, but you are not the first to bring it up. > > -Steve The ambiguity is that `this` resolves to a type in aggregates: ``` class Foo { alias FooToo = this; static assert(is(FooToo == Foo)); } ``` Fortunately this is being removed from the language see: https://github.com/dlang/dmd/commit/524a924477fa02bc2ff11de085f93ab657377d0a |
Copyright © 1999-2021 by the D Language Foundation