digitalmars.D.learn - Preferred Alias Declaration Style
- Vijay Nayar (12/12) Jun 27 2018 Most of the documentation at
- Uknown (6/18) Jun 27 2018 `alias Alias = SomeType;` is preferred. It is the new style, and
- Basile B. (5/26) Jun 27 2018 aliasing a function type only works with the old syntax too:
- Steven Schveighoffer (5/8) Jun 27 2018 IIRC, there was an ambiguity for using the new syntax for alias this. I
- Basile B. (12/20) Jun 27 2018 The ambiguity is that `this` resolves to a type in aggregates:
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?
Jun 27 2018
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.
Jun 27 2018
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").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.
Jun 27 2018
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:You can use this syntax for functions : `alias proto_identifier = void function();`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").[...]
Jun 27 2018
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: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.On Wednesday, 27 June 2018 at 12:25:26 UTC, Uknown wrote:You can use this syntax for functions : `alias proto_identifier = void function();`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").[...]
Jun 27 2018
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:Didn't know that, I assumed that the old style also declared a function pointerOn Wednesday, 27 June 2018 at 14:01:06 UTC, Basile B. 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.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:[...]
Jun 27 2018
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:Ah s**t i meant - proto_identifier_old is a function type (stuff) - proto_identifier_new is a function **pointer** typeOn Wednesday, 27 June 2018 at 14:01:06 UTC, Basile B. 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.[...]You can use this syntax for functions : `alias proto_identifier = void function();`
Jun 27 2018
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
Jun 27 2018
On Wednesday, 27 June 2018 at 15:27:09 UTC, Steven Schveighoffer wrote:On 6/27/18 6:22 AM, Vijay Nayar wrote: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/524a924477fa02bc2ff11de085f93ab657377d0aDoes 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
Jun 27 2018