alias A = B; syntax

Era Scarecrow rtcvb32 at yahoo.com
Tue Oct 16 09:32:01 PDT 2012


On Tuesday, 16 October 2012 at 07:52:51 UTC, Rob T wrote:
> alias int Int;
> Int x = 0;
>
> vs
>
> alias Int = int;
> Int x = 0;
>
> When I compare the two in this way, I'm inclined to keep things 
> as they are.

  alias Int = int;

  this looks too much like variable declaration and instantiation, 
perhaps with only one it looks better to go this way. But what if 
you need several? Perhaps an unrealistic example, let's increase 
it by a factor of seven.

alias SomeChar = char;
alias SomeShort = short;
alias SomeInt = int;
alias SomeUInt = uint;
alias SomeLong = long;
alias SomeFloat = float;
alias SomeDouble = double;
uint  MaybeBroken = nutmeg;
const SomeChar FavoriateLanguage = 'D';
const SomeShort universeAndEverything = 42;
const SomeInt hundredThousand = 100_000;
const SomeUInt million = SomeInt * 10;
const SomeLong largeNumber = SomeUInt * SomeUInt;
const SomeFloat pi = 3.14;
const SomeDouble pi2 = pi*pi;
const MaybeBroken maybe= 2;

or

alias SomeChar = char;
const SomeChar FavoriateLanguage = 'D';
alias SomeShort = short;
const SomeShort universeAndEverything = 42;
alias SomeInt = int;
const SomeInt hundredThousand = 100_000;
alias SomeUInt = uint;
const SomeUInt million = SomeInt * 10;
uint  MaybeBroken = nutmeg;
const MaybeBroken maybeBroke = 2;
alias SomeLong = long;
const SomeLong largeNumber = SomeUInt * SomeUInt;
alias SomeFloat = float;
const SomeFloat pi = 3.14;
alias SomeDouble = double;
const SomeDouble pi2 = pi*pi;

vs

alias char SomeChar;
alias short SomeShort;
alias int SomeInt;
alias uint SomeUInt;
alias long SomeLong;
alias float SomeFloat;
alias double SomeDouble;
alias nutmeg MaybeBroken;
const SomeChar FavoriateLanguage = 'D';
const SomeShort universeAndEverything = 42;
const SomeInt hundredThousand = 100_000;
const SomeUInt million = SomeInt * 10;
const SomeLong largeNumber = SomeUInt * SomeUInt;
const SomeFloat pi = 3.14;
const SomeDouble pi2 = pi*pi;
const MaybeBroken maybeBroken = 2;

or

alias char SomeChar;
const SomeChar FavoriateLanguage = 'D';
alias short SomeShort;
const SomeShort universeAndEverything = 42;
alias int SomeInt;
const SomeInt hundredThousand = 100_000;
alias nutmeg MaybeBroken;
const MaybeBroken maybeBroken = 2;
alias uint SomeUInt;
const SomeUInt million = SomeInt * 10;
alias long SomeLong;
const SomeLong largeNumber = SomeUInt * SomeUInt;
alias float SomeFloat;
const SomeFloat pi = 3.14;
alias double SomeDouble;
const SomeDouble pi2 = pi*pi;


  Without the assignment operator it stands out a little more of 
it's intention and not a variable declaration. But honestly both 
work, I wouldn't mind having the alternate syntax (as long as the 
language doesn't clutter and break anything).


More information about the Digitalmars-d mailing list