digitalmars.D - alias A = B; syntax
- stas (9/9) Oct 15 2012 For me syntax alias int Int; seems unnatural.
- bearophile (7/9) Oct 15 2012 You are not the first one to suggest similar ideas :-)
- Nick Sabalausky (5/16) Oct 15 2012 I'm pretty sure it was already decided that this would be added, but
- Andrej Mitrovic (3/6) Oct 15 2012 Yep.
- Timon Gehr (2/8) Oct 16 2012 This can be implemented in the parser, so it is quite simple.
- Marco Leise (6/16) Oct 15 2012 Just recently I wondered how the current syntax could possibly
- Jonathan M Davis (3/5) Oct 15 2012 It's the same as C's typedef syntax.
- Rob T (24/29) Oct 15 2012 Alias is not the same thing as C's typedef, but I understand it
- Jonathan M Davis (13/26) Oct 15 2012 The syntax is identical except for it being "alias" rather than "typedef...
- Rob T (16/21) Oct 16 2012 Different, as in the ways you've mentioned :)
- Era Scarecrow (77/84) Oct 16 2012 alias Int = int;
- Nick Sabalausky (8/26) Oct 16 2012 Actually, that's the reason I've always preferred the idea of "alias
- Adam D. Ruppe (4/6) Oct 16 2012 I often have to read it to myself in a sentence, like, literally
- Jonathan M Davis (10/12) Oct 15 2012 We'd have to dig through the newsgroup archives to be sure on that one. ...
- Andrej Mitrovic (2/3) Oct 15 2012 Nah just ask Andrei he already confirmed this once.
- Andrei Alexandrescu (4/7) Oct 17 2012 And I confirm again.
- Chris Nicholson-Sauls (13/13) Oct 17 2012 I would generally be pretty 'meh' on an enhancement like this, if
- Don Clugston (13/29) Oct 16 2012 That's my recollection too. I find that even after using it for years, I...
- kenji hara (4/10) Oct 16 2012 The result of my challenging.
- so (6/9) Oct 16 2012 As far as i remember, Andrei said that it was planned and the
- Nick Sabalausky (6/19) Oct 16 2012 I think we can save that as a separate enhancement, especially since
- stas (2/4) Oct 16 2012 Respect.
- Andrej Mitrovic (2/4) Oct 16 2012 Awesome. :)
- Tommi (7/11) Oct 16 2012 You can cast your vote for the new syntax over there:
- stas (6/8) Oct 16 2012 That is awesome. I didn't know about that issue.
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?
Oct 15 2012
stas:Does anybody share this opinion? Any chance this syntax goes into D someday?You are not the first one to suggest similar ideas :-) I think the general answer is: "Not big enough improvement to justify a language change". But I agree your syntax is better. Maybe it's too much late to change it now. Bye, bearophile
Oct 15 2012
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.
Oct 15 2012
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!
Oct 15 2012
On 10/16/2012 06:01 AM, Andrej Mitrovic wrote:On 10/16/12, Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> wrote:This can be implemented in the parser, so it is quite simple.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!
Oct 16 2012
Am Mon, 15 Oct 2012 23:18:33 -0400 schrieb Nick Sabalausky <SeeWebsiteToContactMe semitwist.com>:On Tue, 16 Oct 2012 05:00:56 +0200 "stas" <stasoid yahoo.com> wrote:Just recently I wondered how the current syntax could possibly have come into existence. >) -- MarcoDoes 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.
Oct 15 2012
On Tuesday, October 16, 2012 06:08:27 Marco Leise wrote:Just recently I wondered how the current syntax could possibly have come into existence. >)It's the same as C's typedef syntax. - Jonathn M Davis
Oct 15 2012
On Tuesday, 16 October 2012 at 04:32:29 UTC, Jonathan M Davis wrote:On Tuesday, October 16, 2012 06:08:27 Marco Leise wrote:Alias is not the same thing as C's typedef, but I understand it originally evolved out that way from C's version of typedef. I agree that the current syntax does at first seem inconsistent with most other things in the language, and I found myself typing it in reverse with the = when I first tried using it, eg alias Int = int; On the other hand, I could argue that variable declarations are also inconsistent in the same way, eg int i; // the "declare" keyword is implied instead of declare i = int; So alias int Int; is indeed rather consistent with how type declarations are currently done. Unfortunately, inconsistencies create needless waste, but fixing something like that may be not worth the gain once it becomes deeply rooted in the language. It may not be to late to change the syntax for alias definitions, but the type declarations will no doubt remain as they are, and the rest of it that is the reverse of type declarations will also likely remain as they are. --rtJust recently I wondered how the current syntax could possibly have come into existence. >)It's the same as C's typedef syntax. - Jonathn M Davis
Oct 15 2012
On Tuesday, October 16, 2012 07:17:54 Rob T wrote:On Tuesday, 16 October 2012 at 04:32:29 UTC, Jonathan M Davis wrote:The syntax is identical except for it being "alias" rather than "typedef" and their usage is near identical. C/C++ will allow you to typedef struct declarations instead of just their name typedef struct {...} name; which D won't let you do, and D will let you alias any symbol, whereas C/C++'s typedef only works on types. But since neither actually declares a new type, 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. Regardless, my point was that the syntax was the same and so that's where alias' syntax comes from. - Jonathan M DavisOn Tuesday, October 16, 2012 06:08:27 Marco Leise wrote:Alias is not the same thing as C's typedef, but I understand it originally evolved out that way from C's version of typedef.Just recently I wondered how the current syntax could possibly have come into existence. >)It's the same as C's typedef syntax. - Jonathn M Davis
Oct 15 2012
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
Oct 16 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).
Oct 16 2012
On Tue, 16 Oct 2012 18:32:01 +0200 "Era Scarecrow" <rtcvb32 yahoo.com> wrote: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;Actually, that's the reason I've always preferred the idea of "alias NewSym = OldSym;" Well, that and because with the current syntax I always have to stop and think "Ok, was it 'New then Old' or 'Old then New'?" I do know it's "alias OldSym NewSym;", but I always have to stop and think about it first. I even had to stop and think about it writing that sentence!
Oct 16 2012
On Tuesday, 16 October 2012 at 21:30:27 UTC, Nick Sabalausky wrote:Well, that and because with the current syntax I always have to stop and think "Ok, was it 'New then Old' or 'Old then New'?"I often have to read it to myself in a sentence, like, literally saying to myself: "alias old as new" to get it right.
Oct 16 2012
On Monday, October 15, 2012 23:18:33 Nick Sabalausky wrote:I'm pretty sure it was already decided that this would be added, but just hasn't made it in yet.We'd have to dig through the newsgroup archives to be sure on that one. I'm pretty sure that it _wasn't_ decided that we'd add it, but I don't know for sure. But I don't think that it was entirely shot down either. Personally, I'm so used to the current syntax at this point that I don't much care, and we'd have to add the new syntax on top of the current one (it would break too much code otherwise), which would arguably just complicate the language further. But it's certainly true that plenty of folks would prefer a syntax similar to assignment instead of the current syntax. - Jonathan M Davis
Oct 15 2012
On 10/16/12, Jonathan M Davis <jmdavisProg gmx.com> wrote:We'd have to dig through the newsgroup archivesNah just ask Andrei he already confirmed this once.
Oct 15 2012
On 10/16/12 1:08 AM, Andrej Mitrovic wrote:On 10/16/12, Jonathan M Davis<jmdavisProg gmx.com> wrote:And I confirm again. https://github.com/D-Programming-Language/dmd/pull/1187#issuecomment-9526522 AndreiWe'd have to dig through the newsgroup archivesNah just ask Andrei he already confirmed this once.
Oct 17 2012
I would generally be pretty 'meh' on an enhancement like this, if not for the umpteen times I've aliased rather complex (read: long) types/template-instances and found myself thinking it would be nice for the new name to be at the (visually grep'able) beginning of the declaration. Consider simple example: alias pipe!( readText, splitLines, map!( e => e.splitter( ',' ) ), array ) readRows; alias readRows = pipe!( readText, splitLines, map!( e => e.splitter( ',' ) ), array ); So ultimately I'm happy to see the change, even if it isn't high on the priority list imho. -- Chris Nicholson-Sauls
Oct 17 2012
On 16/10/12 05:18, Nick Sabalausky wrote:On Tue, 16 Oct 2012 05:00:56 +0200 "stas" <stasoid yahoo.com> wrote: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.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.
Oct 16 2012
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?
Oct 16 2012
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. :)
Oct 16 2012
2012/10/16 Andrej Mitrovic <andrej.mitrovich gmail.com>:On 10/16/12, Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> wrote:The result of my challenging. https://github.com/D-Programming-Language/dmd/pull/1187 Kenji HaraI'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!
Oct 16 2012
On Tuesday, 16 October 2012 at 17:05:14 UTC, kenji hara wrote:The result of my challenging. https://github.com/D-Programming-Language/dmd/pull/1187 Kenji HaraAs far as i remember, Andrei said that it was planned and the syntax will support templates too (like C++0x template alias). So, this might not be enough. Something like: alias vec(T) = vector!(T, allocator);
Oct 16 2012
On Tue, 16 Oct 2012 20:45:34 +0200 "so" <so so.so> wrote:On Tuesday, 16 October 2012 at 17:05:14 UTC, kenji hara wrote:I think we can save that as a separate enhancement, especially since Walter has said he wants to do the same thing for variables, too (or at least enum manifest constants, anyway): http://forum.dlang.org/thread/jojish$2cm2$1 digitalmars.com?page=7#post-jok8e6:24k13:241:40digitalmars.comThe result of my challenging. https://github.com/D-Programming-Language/dmd/pull/1187 Kenji HaraAs far as i remember, Andrei said that it was planned and the syntax will support templates too (like C++0x template alias). So, this might not be enough. Something like: alias vec(T) = vector!(T, allocator);
Oct 16 2012
On Tuesday, 16 October 2012 at 17:05:14 UTC, kenji hara wrote:The result of my challenging. https://github.com/D-Programming-Language/dmd/pull/1187Respect.
Oct 16 2012
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/1187Awesome. :)
Oct 16 2012
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;
Oct 16 2012
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=3011That 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.
Oct 16 2012