View mode: basic / threaded / horizontal-split · Log in · Help
October 16, 2012
Re: alias A = B; syntax
On Tuesday, 16 October 2012 at 05:27:53 UTC, Jonathan M Davis 
wrote:
> I'm unaware of any real difference between the two other than 
> those I already
> mentioned. They're pretty much the same thing, so I don't know 
> why you're
> saying that they're different.

Different, as in the ways you've mentioned :)

In response to the OP, I initially felt the same way, but it can 
be argued that the current syntax is more applicable to the type 
declaration syntax.

If we compare the proposed alternate syntax with current, which 
is better?

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.

--rt
October 16, 2012
Re: alias A = B; syntax
On 16/10/12 05:18, Nick Sabalausky wrote:
> On Tue, 16 Oct 2012 05:00:56 +0200
> "stas" <stasoid@yahoo.com> wrote:
>
>> For me syntax alias int Int; seems unnatural.
>> I'd love to write
>> alias Int = int;
>> alias fptr = void(int)*;
>>
>> This looks much more readable for me and harmonized with
>> int x = 0;
>> template T(alias A = Object) {...}
>>
>> Does anybody share this opinion?
>> Any chance this syntax goes into D someday?
>
> I'm pretty sure it was already decided that this would be added, but
> just hasn't made it in yet. I've been fairly eager for it. I find the
> current syntax too inconsistent and confusing.
>

That's my recollection too. I find that even after using it for years, I 
still have to pause and think for a moment whenever I see an alias:

alias Foo Bar;
// is this declaring Foo as an alias of Bar? Or Bar as an alias of Foo?
And if I see:
alias Foo int;
it doesn't instantly stand out to me as the wrong way round. There's a 
delay of 1-2 seconds.

Somehow this is something that my brain refuses to see as natural, no 
matter how many times it sees it. Whereas:

alias Bar = Foo;

is instantly clear, even though I've almost never seen it.
October 16, 2012
Re: alias A = B; syntax
On Tuesday, 16 October 2012 at 09:32:49 UTC, Don Clugston wrote:
>
> Somehow this is something that my brain refuses to see as 
> natural, no matter how many times it sees it.

Exactly.

In C inconsistency was even more vivid:
sometimes I saw
#define BOOL int
and other times
typedef int Bool;  // what a heck?
October 16, 2012
Re: alias A = B; syntax
On Tuesday, 16 October 2012 at 09:32:49 UTC, Don Clugston wrote:
> Somehow this is something that my brain refuses to see as 
> natural, no matter how many times it sees it. Whereas:
>
> alias Bar = Foo;
>
> is instantly clear, even though I've almost never seen it.

+1 to that. :)
October 16, 2012
Re: alias A = B; syntax
On 10/16/2012 06:01 AM, Andrej Mitrovic wrote:
> On 10/16/12, Nick Sabalausky <SeeWebsiteToContactMe@semitwist.com> wrote:
>> I'm pretty sure it was already decided that this would be added, but
>> just hasn't made it in yet. I've been fairly eager for it. I find the
>> current syntax too inconsistent and confusing.
>
> Yep.
>
> Paging Dr. Kenji!
>

This can be implemented in the parser, so it is quite simple.
October 16, 2012
Re: alias A = B; syntax
On Tuesday, 16 October 2012 at 03:00:57 UTC, stas wrote:
> For me syntax alias int Int; seems unnatural.
> I'd love to write
> alias Int = int;
> alias fptr = void(int)*;

You can cast your vote for the new syntax over there:
http://d.puremagic.com/issues/show_bug.cgi?id=3011


By the way, in C++11 you can now also say:

using MyRealType = double;

...instead of:

typedef double MyRealType;
October 16, 2012
Re: alias A = B; syntax
On Tuesday, 16 October 2012 at 14:45:41 UTC, Tommi wrote:
> You can cast your vote for the new syntax over there:
> http://d.puremagic.com/issues/show_bug.cgi?id=3011
>

That is awesome. I didn't know about that issue.
Let's vote, guys!

The issue have been there from 2009 and has only 5 votes.
I am sure if more people knew about it the number of votes would 
be much greater.
October 16, 2012
Re: alias A = B; syntax
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).
October 16, 2012
Re: alias A = B; syntax
2012/10/16 Andrej Mitrovic <andrej.mitrovich@gmail.com>:
> On 10/16/12, Nick Sabalausky <SeeWebsiteToContactMe@semitwist.com> wrote:
>> I'm pretty sure it was already decided that this would be added, but
>> just hasn't made it in yet. I've been fairly eager for it. I find the
>> current syntax too inconsistent and confusing.
>
> Yep.
>
> Paging Dr. Kenji!

The result of my challenging.
https://github.com/D-Programming-Language/dmd/pull/1187

Kenji Hara
October 16, 2012
Re: alias A = B; syntax
On 10/16/12, kenji hara <k.hara.pg@gmail.com> wrote:
> The result of my challenging.
> https://github.com/D-Programming-Language/dmd/pull/1187

Awesome. :)
1 2 3
Top | Discussion index | About this forum | D home