On Friday, 20 October 2017 at 00:26:19 UTC, bauss wrote:
On Wednesday, 18 October 2017 at 08:56:21 UTC, Satoshi wrote:
conditional dereferencing and stuff about that (same as in C#)
...
...
implement this thing from C# (just because it's cool)
new Foo() {
  property1 = 42,
  property2 = "bar"
};



Thanks for your time.
- Satoshi

I really wish this was implemented for classes too! Currently it exist for structs and it completely baffles me why it has never been implemented for structs.

maybe because of open questions. what is with private variables in a class?

At the current time i can set private variables in a D-struct from a different module:

// in amod.d

struct S
{
        private:
immutable       int a = 33;
}


// in bmod.d

S x = { a:1}; // no error
auto y = S( 1); // no error

the D-documentation doesnt tell, if this is valid behaviour of the compiler, whatever, for now I just assume it is.

maybe it is not a good thing to be able to do that. but at the same time the user should decide at object initialization what value _some_ private variables shall have. so, that's what the constructor usually is good for, too. let the user set only certain private variables one time at initialization. with the amod.d-code above there is no way to disallow resetting all private variables.

And: If i can only set public variables, it is not a perfect solution either

Reply via email to