digitalmars.D - -> and :: operators
- Walter Bright (7/7) Oct 08 2015 These, of course, are C++ operators that are replace with the . operator...
- =?UTF-8?Q?Ali_=c3=87ehreli?= (10/17) Oct 08 2015 Semi-relatedly, a colleague who has heard many D sales pitches from me
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (8/15) Oct 09 2015 Just about all higher languages does this, since the reference
- Atila Neves (7/23) Oct 09 2015 The only case in which the C++ way is right is when there are two
- =?UTF-8?Q?Ali_=c3=87ehreli?= (8/21) Oct 09 2015 Yeah... Type properties is another example for D: .sizeof and .alignof
- Freddy (2/13) Oct 09 2015 Stole from D? You mean java right?
- Dmitry Olshansky (4/17) Oct 09 2015 There is no value type objects in Java so no. More likely C#.
- Warwick (3/7) Oct 10 2015 Delphi / Object Pascal had it in the mid 90s IIRC. Long before
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (2/11) Oct 10 2015 Simula is the origin, it came about in the 60s.
- Walter Bright (3/6) Oct 10 2015 Since C# was an internal Microsoft project at the time this was
- Idan Arye (13/35) Oct 11 2015 Nope - C# uses -> to access member of a struct referenced by a
- Warwick (7/12) Oct 11 2015 At the risk of sounding like a broken record the Delphi variant
- Idan Arye (3/16) Oct 11 2015 You should have elaborated then. The other guys talked about the
- Warwick (2/15) Oct 11 2015 Sorry I've been on pills to prevent premature elaboration. :-)
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (17/20) Oct 11 2015 BETA is the successor to Simula and it does not distinguish
- Jeremy DeHaan (2/17) Oct 09 2015 Java doesn't have pointers.
- deadalnix (5/23) Oct 09 2015 -_-
- Jeremy DeHaan (3/15) Oct 09 2015 I guess you could argue it that way, but I don't see references
- Jonathan M Davis (11/28) Oct 09 2015 Java references (as well as C# references and D references) are
- jmh530 (3/4) Oct 08 2015 In the binary case, -> and <- are assignment operators in R. But
- ixid (3/12) Oct 09 2015 Too late to change but wouldn't it be better to have one operator
- Jonathan M Davis (14/17) Oct 09 2015 That would defeat the purpose of _Uniform_ Function Call Syntax.
- ixid (3/5) Oct 09 2015 For some reason I'd thought it didn't work when you mixed member
- Jonathan M Davis (10/17) Oct 09 2015 It works fine in general, and if there's a conflict, it's the
- Andrej Mitrovic (3/12) Oct 11 2015 https://issues.dlang.org/show_bug.cgi?id=15186
These, of course, are C++ operators that are replace with the . operator in D. But when I translate C++ code to D, sometimes these operators get left behind, and sometimes I simply reflexively type them into D code. The error message coming out of dmd could be better. I suggest recognizing -> and :: in the lexer, and saying something like: "The '->' operator is not in D, did you mean '.'?" Anyone want to do a PR for this? (Should be pretty straightforward.)
Oct 08 2015
On 10/08/2015 08:41 PM, Walter Bright wrote:These, of course, are C++ operators that are replace with the . operator in D. But when I translate C++ code to D, sometimes these operators get left behind, and sometimes I simply reflexively type them into D code. The error message coming out of dmd could be better. I suggest recognizing -> and :: in the lexer, and saying something like: "The '->' operator is not in D, did you mean '.'?" Anyone want to do a PR for this? (Should be pretty straightforward.)Semi-relatedly, a colleague who has heard many D sales pitches from me over the years is recently "looking at Go" and liking it very much. He came to me today telling me about this awesome Go feature where you just type a dot after a pointer and the language is so great that it works! You don't need to type (*p).member. Isn't Go awesome! I responded "yep, it's a great feature and those gostards will never admit that they took that feature from D." (There is probably earlier precedence but it felt great to say it to my friend. :) ) Ali
Oct 08 2015
On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:Go feature where you just type a dot after a pointer and the language is so great that it works! You don't need to type (*p).member. Isn't Go awesome! I responded "yep, it's a great feature and those gostards will never admit that they took that feature from D." (There is probably earlier precedence but it felt great to say it to my friend. :) )Just about all higher languages does this, since the reference type does not have members. Simula too. But this unfortunately breaks down when you add smart-pointers, which makes this approach unsound since pointer-type members collide with object members. So C++ actually got this right by requiring explicit dereferencing.
Oct 09 2015
On Friday, 9 October 2015 at 12:19:55 UTC, Ola Fosheim Grøstad wrote:On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:The only case in which the C++ way is right is when there are two member functions of the same name in the pointed-to object and the smart pointer itself since you can disambiguate `ptr->get()` from `ptr.get()`. AtilaGo feature where you just type a dot after a pointer and the language is so great that it works! You don't need to type (*p).member. Isn't Go awesome! I responded "yep, it's a great feature and those gostards will never admit that they took that feature from D." (There is probably earlier precedence but it felt great to say it to my friend. :) )Just about all higher languages does this, since the reference type does not have members. Simula too. But this unfortunately breaks down when you add smart-pointers, which makes this approach unsound since pointer-type members collide with object members. So C++ actually got this right by requiring explicit dereferencing.
Oct 09 2015
On 10/09/2015 05:19 AM, Ola Fosheim Grøstad wrote:On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:Yeah... Type properties is another example for D: .sizeof and .alignof are not propagated to the pointee and .stringof is not propagated to the type of the pointee. Similarly, for class references, one must remember to use __traits(classInstanceSize) and std.traits.classInstanceAlignment. (Yes, I notice the inconsistency. ;) ) AliGo feature where you just type a dot after a pointer and the language is so great that it works! You don't need to type (*p).member. Isn't Go awesome! I responded "yep, it's a great feature and those gostards will never admit that they took that feature from D." (There is probably earlier precedence but it felt great to say it to my friend. :) )Just about all higher languages does this, since the reference type does not have members. Simula too. But this unfortunately breaks down when you add smart-pointers, which makes this approach unsound since pointer-type members collide with object members.
Oct 09 2015
On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:Semi-relatedly, a colleague who has heard many D sales pitches from me over the years is recently "looking at Go" and liking it very much. He came to me today telling me about this awesome Go feature where you just type a dot after a pointer and the language is so great that it works! You don't need to type (*p).member. Isn't Go awesome! I responded "yep, it's a great feature and those gostards will never admit that they took that feature from D." (There is probably earlier precedence but it felt great to say it to my friend. :) ) AliStole from D? You mean java right?
Oct 09 2015
On 09-Oct-2015 21:44, Freddy wrote:On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:-- Dmitry OlshanskySemi-relatedly, a colleague who has heard many D sales pitches from me over the years is recently "looking at Go" and liking it very much. He came to me today telling me about this awesome Go feature where you just type a dot after a pointer and the language is so great that it works! You don't need to type (*p).member. Isn't Go awesome! I responded "yep, it's a great feature and those gostards will never admit that they took that feature from D." (There is probably earlier precedence but it felt great to say it to my friend. :) ) AliStole from D? You mean java right?
Oct 09 2015
On Friday, 9 October 2015 at 19:48:39 UTC, Dmitry Olshansky wrote:On 09-Oct-2015 21:44, Freddy wrote:Delphi / Object Pascal had it in the mid 90s IIRC. Long beforeStole from D? You mean java right?
Oct 10 2015
On Saturday, 10 October 2015 at 22:54:15 UTC, Warwick wrote:On Friday, 9 October 2015 at 19:48:39 UTC, Dmitry Olshansky wrote:Simula is the origin, it came about in the 60s.On 09-Oct-2015 21:44, Freddy wrote:Delphi / Object Pascal had it in the mid 90s IIRC. Long beforeStole from D? You mean java right?
Oct 10 2015
On 10/9/2015 12:48 PM, Dmitry Olshansky wrote:On 09-Oct-2015 21:44, Freddy wrote:developed for D, no.Stole from D? You mean java right?
Oct 10 2015
On Friday, 9 October 2015 at 19:48:39 UTC, Dmitry Olshansky wrote:On 09-Oct-2015 21:44, Freddy wrote:pointer. See https://msdn.microsoft.com/en-us/library/50sbeks5.aspx The difference between reference types and pointers is that with reference types, THERE ARE NO value varaiables. So it's safe to use . instead of -> for accessing member through a reference because there is no value type, because there is no such a thing as accessing a member of a reference type without dereferencing This is the innovation in D(regarding this issue) - that on struct types, the same operator is used for BOTH the value type and the pointer to it.On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:Semi-relatedly, a colleague who has heard many D sales pitches from me over the years is recently "looking at Go" and liking it very much. He came to me today telling me about this awesome Go feature where you just type a dot after a pointer and the language is so great that it works! You don't need to type (*p).member. Isn't Go awesome! I responded "yep, it's a great feature and those gostards will never admit that they took that feature from D." (There is probably earlier precedence but it felt great to say it to my friend. :) ) AliStole from D? You mean java right?
Oct 11 2015
On Sunday, 11 October 2015 at 09:43:04 UTC, Idan Arye wrote:On Friday, 9 October 2015 at 19:48:39 UTC, Dmitry Olshansky wrote: This is the innovation in D(regarding this issue) - that on struct types, the same operator is used for BOTH the value type and the pointer to it.At the risk of sounding like a broken record the Delphi variant of Object Pascal started doing that some time around Delphi 4 or Delphi 5 IIRC. (So mid to late 90s). IE. You accessed members with the dot operator whether it was an object (like D Delphi's objects are heap based / reference semantics), a struct, or a pointer to a struct.
Oct 11 2015
On Sunday, 11 October 2015 at 13:05:41 UTC, Warwick wrote:On Sunday, 11 October 2015 at 09:43:04 UTC, Idan Arye wrote:You should have elaborated then. The other guys talked about the invention of reference types, so I assumed you did as well.On Friday, 9 October 2015 at 19:48:39 UTC, Dmitry Olshansky wrote: This is the innovation in D(regarding this issue) - that on struct types, the same operator is used for BOTH the value type and the pointer to it.At the risk of sounding like a broken record the Delphi variant of Object Pascal started doing that some time around Delphi 4 or Delphi 5 IIRC. (So mid to late 90s). IE. You accessed members with the dot operator whether it was an object (like D Delphi's objects are heap based / reference semantics), a struct, or a pointer to a struct.
Oct 11 2015
On Sunday, 11 October 2015 at 13:50:18 UTC, Idan Arye wrote:On Sunday, 11 October 2015 at 13:05:41 UTC, Warwick wrote:Sorry I've been on pills to prevent premature elaboration. :-)On Sunday, 11 October 2015 at 09:43:04 UTC, Idan Arye wrote:You should have elaborated then. The other guys talked about the invention of reference types, so I assumed you did as well.On Friday, 9 October 2015 at 19:48:39 UTC, Dmitry Olshansky wrote:At the risk of sounding like a broken record the Delphi variant of Object Pascal started doing that some time around Delphi 4 or Delphi 5 IIRC. (So mid to late 90s). IE. You accessed members with the dot operator whether it was an object (like D Delphi's objects are heap based / reference semantics), a struct, or a pointer to a struct.
Oct 11 2015
On Sunday, 11 October 2015 at 09:43:04 UTC, Idan Arye wrote:This is the innovation in D(regarding this issue) - that on struct types, the same operator is used for BOTH the value type and the pointer to it.BETA is the successor to Simula and it does not distinguish between value or reference and only use dot reference. What they do instead of having a dereference operator is to have a "reference operator" and also a "pattern operator" for type variables. So it works something like this: Call a and send the output as the input to b and then store the result: (1,(2,3)) -> a -> b -> (c,(d,e)) Assign reference a to b (instanced class/function) a[] -> b[] Replace class-type variable a with class-type b (not instanced, which is equivalent to a class-type/function pointer) It makes a lot of sense for an OO language since we usually use the referenced content more often than we want to change the pointer.
Oct 11 2015
On Friday, 9 October 2015 at 18:44:50 UTC, Freddy wrote:On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:Java doesn't have pointers.Semi-relatedly, a colleague who has heard many D sales pitches from me over the years is recently "looking at Go" and liking it very much. He came to me today telling me about this awesome Go feature where you just type a dot after a pointer and the language is so great that it works! You don't need to type (*p).member. Isn't Go awesome! I responded "yep, it's a great feature and those gostards will never admit that they took that feature from D." (There is probably earlier precedence but it felt great to say it to my friend. :) ) AliStole from D? You mean java right?
Oct 09 2015
On Friday, 9 October 2015 at 19:54:19 UTC, Jeremy DeHaan wrote:On Friday, 9 October 2015 at 18:44:50 UTC, Freddy wrote:-_- Yeah reference are definitively not pointer. No they aren't. No I told you they aren't. Nope. Not even a little ! No way ! That's not true ! I told you that's not true. Nope !On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:Java doesn't have pointers.Semi-relatedly, a colleague who has heard many D sales pitches from me over the years is recently "looking at Go" and liking it very much. He came to me today telling me about this awesome Go feature where you just type a dot after a pointer and the language is so great that it works! You don't need to type (*p).member. Isn't Go awesome! I responded "yep, it's a great feature and those gostards will never admit that they took that feature from D." (There is probably earlier precedence but it felt great to say it to my friend. :) ) AliStole from D? You mean java right?
Oct 09 2015
On Friday, 9 October 2015 at 21:21:10 UTC, deadalnix wrote:On Friday, 9 October 2015 at 19:54:19 UTC, Jeremy DeHaan wrote:I guess you could argue it that way, but I don't see references and pointers as the same. Similar, yes, but not the same.On Friday, 9 October 2015 at 18:44:50 UTC, Freddy wrote:-_- Yeah reference are definitively not pointer. No they aren't. No I told you they aren't. Nope. Not even a little ! No way ! That's not true ! I told you that's not true. Nope !On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:Java doesn't have pointers.[...]Stole from D? You mean java right?
Oct 09 2015
On Friday, 9 October 2015 at 23:57:28 UTC, Jeremy DeHaan wrote:On Friday, 9 October 2015 at 21:21:10 UTC, deadalnix wrote:managed pointers. Their only real differences from "normal" pointers are that they're managed by the GC, you can't assign an address to them (except by assigning another reference to them), and that you can't dereference them except when accessing one of their members. There's no question that per the computer science definition of a pointer, they qualify. They just aren't quite what you get in C/C++ or from D's pointers which aren't class references. - Jonathan M DavisOn Friday, 9 October 2015 at 19:54:19 UTC, Jeremy DeHaan wrote:I guess you could argue it that way, but I don't see references and pointers as the same. Similar, yes, but not the same.On Friday, 9 October 2015 at 18:44:50 UTC, Freddy wrote:-_- Yeah reference are definitively not pointer. No they aren't. No I told you they aren't. Nope. Not even a little ! No way ! That's not true ! I told you that's not true. Nope !On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:Java doesn't have pointers.[...]Stole from D? You mean java right?
Oct 09 2015
On Friday, 9 October 2015 at 03:41:42 UTC, Walter Bright wrote:"The '->' operator is not in D, did you mean '.'?"In the binary case, -> and <- are assignment operators in R. But I imagine you don't want to go crazy with these sorts of messages.
Oct 08 2015
On Friday, 9 October 2015 at 03:41:42 UTC, Walter Bright wrote:These, of course, are C++ operators that are replace with the . operator in D. But when I translate C++ code to D, sometimes these operators get left behind, and sometimes I simply reflexively type them into D code. The error message coming out of dmd could be better. I suggest recognizing -> and :: in the lexer, and saying something like: "The '->' operator is not in D, did you mean '.'?" Anyone want to do a PR for this? (Should be pretty straightforward.)Too late to change but wouldn't it be better to have one operator for members and another for UFCS? '->' would be good for UFCS.
Oct 09 2015
On Friday, 9 October 2015 at 10:03:18 UTC, ixid wrote:Too late to change but wouldn't it be better to have one operator for members and another for UFCS? '->' would be good for UFCS.That would defeat the purpose of _Uniform_ Function Call Syntax. The whole point is that it uses the same syntax for member functions and free functions. In many cases, it's just for aesthetic purposes, but with templated code, it can be critical, because it allows you to effectively overload a free function with a member function (e.g. a particular range type could overload find if it had a more efficient implementation for it than the one in std.algorithm). It also makes it so that a type which doesn't have member functions can work in a template that's expecting the type to have specific member functions (e.g. arrays use free functions for the range primitives, but they're normally used as if they were member functions). - Jonathan M Davis
Oct 09 2015
On Friday, 9 October 2015 at 10:15:42 UTC, Jonathan M Davis wrote:That would defeat the purpose of _Uniform_ Function Call Syntax...For some reason I'd thought it didn't work when you mixed member function calls with function calls but it seems to do so smoothly.
Oct 09 2015
On Friday, 9 October 2015 at 10:42:03 UTC, ixid wrote:On Friday, 9 October 2015 at 10:15:42 UTC, Jonathan M Davis wrote:It works fine in general, and if there's a conflict, it's the member function that gets called. So, if you want to guarantee that it's a particular free function that gets called, you need to not use UFCS (and possibly provide the full import path when using it). But in most cases, it's desirable for a member function to be able able to override the behavior of a free function. The main problem is when they happen to match but do completely different things. - Jonathan M DavisThat would defeat the purpose of _Uniform_ Function Call Syntax...For some reason I'd thought it didn't work when you mixed member function calls with function calls but it seems to do so smoothly.
Oct 09 2015
On Friday, 9 October 2015 at 03:41:42 UTC, Walter Bright wrote:These, of course, are C++ operators that are replace with the . operator in D. But when I translate C++ code to D, sometimes these operators get left behind, and sometimes I simply reflexively type them into D code. The error message coming out of dmd could be better. I suggest recognizing -> and :: in the lexer, and saying something like: "The '->' operator is not in D, did you mean '.'?" Anyone want to do a PR for this? (Should be pretty straightforward.)https://issues.dlang.org/show_bug.cgi?id=15186 https://github.com/D-Programming-Language/dmd/pull/5190
Oct 11 2015