Thread overview
Modify Object Pointer during Initialzation
Apr 08, 2014
Jeroen Bollen
Apr 08, 2014
Adam D. Ruppe
Apr 08, 2014
Jeroen Bollen
Apr 08, 2014
Adam D. Ruppe
Apr 08, 2014
Jeroen Bollen
Apr 08, 2014
Jeroen Bollen
April 08, 2014
This topic is somewhat related to this question I asked yesterday on StackOverflow: http://stackoverflow.com/q/22921395/2558778

Basically, why is this its own variable? Why doesn't D simply use the variable it was called with?

https://gist.github.com/Binero/10128826

I don't see why this needs to be a new variable and cannot simply be 'passed-by-reference'.
April 08, 2014
On Tuesday, 8 April 2014 at 14:04:01 UTC, Jeroen Bollen wrote:
> Basically, why is this its own variable? Why doesn't D simply use the variable it was called with?

A class reference is basically a pointer, passing it by reference to each method would be a double pointer and wasted effort most the time; all most methods care about is where to get the object data, they don't need to know how the caller was getting to the object data.

> I don't see why this needs to be a new variable and cannot simply be 'passed-by-reference'.

You can get that with UFCS btw:

class A {}

void f(ref A a) { /* modify a here and it will change */ }

void main() {
  A a = new A;
  a.f; // a is passed by reference
}
April 08, 2014
On Tuesday, 8 April 2014 at 14:13:10 UTC, Adam D. Ruppe wrote:
> On Tuesday, 8 April 2014 at 14:04:01 UTC, Jeroen Bollen wrote:
>> Basically, why is this its own variable? Why doesn't D simply use the variable it was called with?
>
> A class reference is basically a pointer, passing it by reference to each method would be a double pointer and wasted effort most the time; all most methods care about is where to get the object data, they don't need to know how the caller was getting to the object data.
>
>> I don't see why this needs to be a new variable and cannot simply be 'passed-by-reference'.
>
> You can get that with UFCS btw:
>
> class A {}
>
> void f(ref A a) { /* modify a here and it will change */ }
>
> void main() {
>   A a = new A;
>   a.f; // a is passed by reference
> }

Is there a documentation page about the 'uniform function call syntax'?
April 08, 2014
On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
> Is there a documentation page about the 'uniform function call syntax'?

http://dlang.org/function.html#pseudo-member
April 08, 2014
On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
> Is there a documentation page about the 'uniform function call syntax'?

Never mind, I think I understand all there is to it.
April 08, 2014
On Tuesday, 8 April 2014 at 14:26:46 UTC, Adam D. Ruppe wrote:
> On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
>> Is there a documentation page about the 'uniform function call syntax'?
>
> http://dlang.org/function.html#pseudo-member

Oh beat me to it.