Re: alias A = B; syntax
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
Re: alias A = B; syntax
On 10/16/12 1:08 AM, Andrej Mitrovic wrote: On 10/16/12, Jonathan M Davis wrote: We'd have to dig through the newsgroup archives Nah just ask Andrei he already confirmed this once. And I confirm again. https://github.com/D-Programming-Language/dmd/pull/1187#issuecomment-9526522 Andrei
Re: alias A = B; syntax
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.
Re: alias A = B; syntax
On Tue, 16 Oct 2012 20:45:34 +0200 "so" wrote: > 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 Hara > > As 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); 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.com
Re: alias A = B; syntax
On Tue, 16 Oct 2012 18:32:01 +0200 "Era Scarecrow" 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!
Re: alias A = B; syntax
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 Respect.
Re: alias A = B; syntax
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 Hara As 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);
Re: alias A = B; syntax
On 10/16/12, kenji hara wrote: > The result of my challenging. > https://github.com/D-Programming-Language/dmd/pull/1187 Awesome. :)
Re: alias A = B; syntax
2012/10/16 Andrej Mitrovic : > On 10/16/12, Nick Sabalausky 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
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).
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.
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;
Re: alias A = B; syntax
On 10/16/2012 06:01 AM, Andrej Mitrovic wrote: On 10/16/12, Nick Sabalausky 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.
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. :)
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?
Re: alias A = B; syntax
On 16/10/12 05:18, Nick Sabalausky wrote: On Tue, 16 Oct 2012 05:00:56 +0200 "stas" 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.
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
Re: alias A = B; syntax
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: > > 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 > > 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. 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 Davis
Re: alias A = B; syntax
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: 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 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. --rt
Re: alias A = B; syntax
On 10/16/12, Jonathan M Davis wrote: > We'd have to dig through the newsgroup archives Nah just ask Andrei he already confirmed this once.
Re: alias A = B; syntax
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
Re: alias A = B; syntax
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
Re: alias A = B; syntax
Am Mon, 15 Oct 2012 23:18:33 -0400 schrieb Nick Sabalausky : > On Tue, 16 Oct 2012 05:00:56 +0200 > "stas" wrote: > > > 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. > Just recently I wondered how the current syntax could possibly have come into existence. >) -- Marco
Re: alias A = B; syntax
On 10/16/12, Nick Sabalausky 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!
Re: alias A = B; syntax
On Tue, 16 Oct 2012 05:00:56 +0200 "stas" 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.
Re: alias A = B; syntax
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
alias A = B; syntax
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?