www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - `alias newSymbol = existingSymbol` or `alias existingSymbol newSymbol`

reply "Mike" <none none.com> writes:
A debate is currently taking place over `alias newSymbol = 
existingSymbol` (a.k.a "The new syntax") or `alias existingSymbol 
newSymbol` (a.k.a "The old syntax") in a pull request to update 
the D Style guide, and a pull request to update druntime's code. 
It has been suggested to bring this to a larger audience, and 
that request motivated this post.

IMPORTANT:
No one is recommending deprecation of the old syntax.  That is an 
entirely separate issue for another place and another time.

Background:
* Enhancement 3011 [3] - Submitted in May 2009
* Pull request implementing 3011 [4] - Merged October 2012
* Pull request updating dlang.org code examples [5] - Merged 
February 2014
* Andrei Alexandrescue encourages dfix utility [6] to update code 
to the new syntax [7] - Posted July 2014
* dfix used to update druntime to new syntax [2] - October 2014

[1] - https://github.com/D-Programming-Language/dlang.org/pull/682
[2] - https://github.com/D-Programming-Language/druntime/pull/1002
[3] - https://issues.dlang.org/show_bug.cgi?id=3011
[4] - https://github.com/D-Programming-Language/dmd/pull/1187
[5] - https://github.com/D-Programming-Language/dlang.org/pull/493
[6] - https://github.com/Hackerpilot/dfix
[7] - http://forum.dlang.org/post/lq9sf3$3au$1 digitalmars.com
Oct 27 2014
next sibling parent reply "Mike" <none none.com> writes:
Let's try that again with the correct references:

A debate is currently taking place over `alias newSymbol =
existingSymbol` (a.k.a "The new syntax") or `alias existingSymbol
newSymbol` (a.k.a "The old syntax") in a pull request to update
the D Style guide [1], and a pull request to update druntime's 
code [2].
It has been suggested to bring this to a larger audience, and
that request motivated this post.

IMPORTANT:
No one is recommending deprecation of the old syntax.  That is an
entirely separate issue for another place and another time.

Background:
* Enhancement 3011 [3] - Submitted in May 2009
* Pull request implementing 3011 [4] - Merged October 2012
* Pull request updating dlang.org code examples [5] - Merged
February 2014
* Andrei Alexandrescue encourages dfix utility [6] to update code
to the new syntax [7] - Posted July 2014
* dfix used to update druntime to new syntax [2] - October 2014

[1] - https://github.com/D-Programming-Language/dlang.org/pull/682
[2] - https://github.com/D-Programming-Language/druntime/pull/1002
[3] - https://issues.dlang.org/show_bug.cgi?id=3011
[4] - https://github.com/D-Programming-Language/dmd/pull/1187
[5] - https://github.com/D-Programming-Language/dlang.org/pull/493
[6] - https://github.com/Hackerpilot/dfix
[7] - http://forum.dlang.org/post/lq9sf3$3au$1 digitalmars.com
Oct 27 2014
parent "Trass3r" <un known.com> writes:
Let the bikeshedding begin.
They treat the style guide like the holy bible.
Oct 28 2014
prev sibling parent reply Jonathan M Davis via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Tuesday, October 28, 2014 00:55:30 Mike via Digitalmars-d wrote:
 A debate is currently taking place over `alias newSymbol =
 existingSymbol` (a.k.a "The new syntax") or `alias existingSymbol
 newSymbol` (a.k.a "The old syntax") in a pull request to update
 the D Style guide, and a pull request to update druntime's code.
 It has been suggested to bring this to a larger audience, and
 that request motivated this post.

 IMPORTANT:
 No one is recommending deprecation of the old syntax.  That is an
 entirely separate issue for another place and another time.

 Background:
 * Enhancement 3011 [3] - Submitted in May 2009
 * Pull request implementing 3011 [4] - Merged October 2012
 * Pull request updating dlang.org code examples [5] - Merged
 February 2014
 * Andrei Alexandrescue encourages dfix utility [6] to update code
 to the new syntax [7] - Posted July 2014
 * dfix used to update druntime to new syntax [2] - October 2014

 [1] - https://github.com/D-Programming-Language/dlang.org/pull/682
 [2] - https://github.com/D-Programming-Language/druntime/pull/1002
 [3] - https://issues.dlang.org/show_bug.cgi?id=3011
 [4] - https://github.com/D-Programming-Language/dmd/pull/1187
 [5] - https://github.com/D-Programming-Language/dlang.org/pull/493
 [6] - https://github.com/Hackerpilot/dfix
 [7] - http://forum.dlang.org/post/lq9sf3$3au$1 digitalmars.com
I see no reason to say anything about the alias syntax in the style guide. It's a formatting issue, and we've tried to keep formatting guidelines out of the style guide (the only one that applies to anything other than Phobos is using 4 spaces instead of tabs for identation, and even Phobos only has two more beyond that - one for the line length and one for the bracing style, neither of which do we want to push on the community at large). If we intend to get rid of the older syntax, then it'll be deprecated in the compiler, and there will be no need to put anything in the style guide anyway. And if we don't intend to deprecate it, then why push the newer one onto people? If they prefer it and want to use it, great. Have at it. But as long as both styles are legal and are intended to stay that way, then arguing over the alias syntax is like arguing over whether for(;;) or while(1) is better for infinite loops. Both are perfectly valid and work just fine. Which you use is a matter of preference. Another example would be UFCS. It's perfectly valid to use it or not, and we don't push either style on anyone. As such, I don't think that it makes any sense to say anything about the alias syntax in the style guide, and I think that changing existing code in druntime or Phobos from one style to another (be it from the old to the new or from the new to the old) is useless churn. It would be like moving all of the function attributes to the left of the function signatures. Doing so provides no real improvement or benefit. It just makes it so that diffs are larger when looking at the repo's history. - Jonathan M Davis
Oct 28 2014
next sibling parent reply "Mike" <none none.com> writes:
On Tuesday, 28 October 2014 at 08:29:22 UTC, Jonathan M Davis via 
Digitalmars-d wrote:
 I see no reason to say anything about the alias syntax in the 
 style guide.
All those that program in D are not required to follow the recommendations in the Style Guide. The Style Guide is for contributors to the official D repositories, so the code there remains consistent and disciplined. It would be helpful to let contributors know what the recommendation is, so they can have confidence that their contribution will pass scrutiny and not have to endure controversy and debate. Mike
Oct 28 2014
parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Tuesday, 28 October 2014 at 08:59:20 UTC, Mike wrote:
 On Tuesday, 28 October 2014 at 08:29:22 UTC, Jonathan M Davis 
 via Digitalmars-d wrote:
 I see no reason to say anything about the alias syntax in the 
 style guide.
All those that program in D are not required to follow the recommendations in the Style Guide. The Style Guide is for contributors to the official D repositories, so the code there remains consistent and disciplined. It would be helpful to let contributors know what the recommendation is, so they can have confidence that their contribution will pass scrutiny and not have to endure controversy and debate.
The style guide is not just for the official repos. It's intended as a recommendation to the community at large - hence why it has a separate section at the bottom specifically for the official repos where the line limit and bracing style are mandated - something that we don't want to mandate for the community at large. Regardless, the old style is perfectly valid, and as long as it remains so, I see no reason to try and push the newer style on anyone. Either it should be considered fine to use, or we should deprecate it. And if it's fine to use it, why create the churn in druntime or Phobos' diffs by changing from one syntax to the other? - Jonathan M Davis
Oct 28 2014
prev sibling parent reply "David Nadlinger" <code klickverbot.at> writes:
On Tuesday, 28 October 2014 at 08:29:22 UTC, Jonathan M Davis via 
Digitalmars-d wrote:
 I see no reason to say anything about the alias syntax in the 
 style guide.
Consistency, and thus less confusion/mental overhead. I don't think that you'll be able to make a strong case for "Either it should be considered fine to use, or we should deprecate it." If we started with a clean slate today, there wouldn't be a good reason to include the old syntax. It is an outlier as we've generally moved away from C-style ordering of types/declarations, and also can't do inline templates. And if we agree that the new syntax is to be preferred – and it seems like except for you we pretty unambiguously do –, I don't see why we shouldn't put that out as an official recommendation. Of course, breaking legacy code over this by deprecating the old syntax might ultimately not be worth it. I don't see how this can be construed as an argument against putting it in the style guide, however. In fact, if we planned to deprecate it anyway, this would rather be a reason _not_ to to bother with putting it in the style guide first. To summarize why the new syntax is better than the old one: - It's more straightforward for newcomers, its order is the same as for basic assignments. If you somehow find that unnatural like you've claimed earlier, then you've merely trained your brain to read alias assignments backwards compared to assign expressions. - Arguably the new syntax also makes it easier to skim-read the code, as the most important part (the symbol introduced) is at the beginning of the line, not hidden after some potentially multi-line template instantiation. Granted, you might say that this is not very relevant, but I think you'd find it hard to argue that the syntax is _less_ readable. - The new syntax also has the advantage that it allows to easily declare template aliases, for example: --- alias Seq(T...) = T; --- By the way, "using" is regularly recommended for use in C++11 and up now instead of "typedef" for much the same reasons (just look at the CppCon talks for some data points). David
Nov 02 2014
parent reply "Tofu Ninja" <emmons0 purdue.edu> writes:
On Monday, 3 November 2014 at 02:43:03 UTC, David Nadlinger wrote:
 On Tuesday, 28 October 2014 at 08:29:22 UTC, Jonathan M Davis 
 via Digitalmars-d wrote:
 I see no reason to say anything about the alias syntax in the 
 style guide.
Consistency, and thus less confusion/mental overhead. I don't think that you'll be able to make a strong case for "Either it should be considered fine to use, or we should deprecate it." If we started with a clean slate today, there wouldn't be a good reason to include the old syntax. It is an outlier as we've generally moved away from C-style ordering of types/declarations, and also can't do inline templates. And if we agree that the new syntax is to be preferred – and it seems like except for you we pretty unambiguously do –, I don't see why we shouldn't put that out as an official recommendation. Of course, breaking legacy code over this by deprecating the old syntax might ultimately not be worth it. I don't see how this can be construed as an argument against putting it in the style guide, however. In fact, if we planned to deprecate it anyway, this would rather be a reason _not_ to to bother with putting it in the style guide first. To summarize why the new syntax is better than the old one: - It's more straightforward for newcomers, its order is the same as for basic assignments. If you somehow find that unnatural like you've claimed earlier, then you've merely trained your brain to read alias assignments backwards compared to assign expressions. - Arguably the new syntax also makes it easier to skim-read the code, as the most important part (the symbol introduced) is at the beginning of the line, not hidden after some potentially multi-line template instantiation. Granted, you might say that this is not very relevant, but I think you'd find it hard to argue that the syntax is _less_ readable. - The new syntax also has the advantage that it allows to easily declare template aliases, for example: --- alias Seq(T...) = T; --- By the way, "using" is regularly recommended for use in C++11 and up now instead of "typedef" for much the same reasons (just look at the CppCon talks for some data points). David
I agree with basically everything you said. I only have one thing I want to say. The only reason the new syntax was introduced is because its an improvement on the old, it would never have been added otherwise. That alone should be reason enough for it to be prefered.
Nov 03 2014
parent Shriramana Sharma via Digitalmars-d <digitalmars-d puremagic.com> writes:
Hello people. FWIW, for those who want to alias one symbol to multiple
other symbols and saying that only the old syntax helps them, how
about allowing alias a = b = c = int? It is merely an extension of the
assignment-based new syntax, no?

-- 
Shriramana Sharma ஶ்ரீரமணஶர்மா
श्रीरमणशर्मा
Nov 03 2014