`alias newSymbol = existingSymbol` or `alias existingSymbol newSymbol`

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 28 01:29:13 PDT 2014


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



More information about the Digitalmars-d mailing list