Re: tupleof seems to break encapsulation

2020-09-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-05 07:14, 60rntogo wrote: I wouldn't dispute that it is useful, but that's besides the point. If I declare something private, it's usually because I want to preserve certain invariants and I want the compiler to provide a guarantee that I don't accidentally violate them. As it

Re: tupleof seems to break encapsulation

2020-09-04 Thread 60rntogo via Digitalmars-d-learn
On Friday, 4 September 2020 at 17:36:00 UTC, Jacob Carlborg wrote: It's useful for serialization and, as you can see in your example, for debugging as well. `writeln` will print the values of the fields in a struct, even for private fields. I wouldn't dispute that it is useful, but that's

Re: tupleof seems to break encapsulation

2020-09-04 Thread Paul Backus via Digitalmars-d-learn
On Friday, 4 September 2020 at 18:23:09 UTC, H. S. Teoh wrote: On Fri, Sep 04, 2020 at 07:36:00PM +0200, Jacob Carlborg via Digitalmars-d-learn wrote: [...] It's useful for serialization and, as you can see in your example, for debugging as well. `writeln` will print the values of the fields

Re: tupleof seems to break encapsulation

2020-09-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 04, 2020 at 07:36:00PM +0200, Jacob Carlborg via Digitalmars-d-learn wrote: [...] > It's useful for serialization and, as you can see in your example, for > debugging as well. `writeln` will print the values of the fields in a > struct, even for private fields. It's certainly useful,

Re: tupleof seems to break encapsulation

2020-09-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-04 12:16, 60rntogo wrote: Consider the following code. foo.d --- module foo; struct Foo {   private int i; } --- main.d --- void main() {   import std.stdio;   import foo;   auto x = Foo();   writeln(x);   // ++x.i;   ++x.tupleof[0];   writeln(x); } --- As expected, the

Re: tupleof seems to break encapsulation

2020-09-04 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 4 September 2020 at 10:16:47 UTC, 60rntogo wrote: Consider the following code. foo.d --- module foo; struct Foo { private int i; } --- main.d --- void main() { import std.stdio; import foo; auto x = Foo(); writeln(x); // ++x.i; ++x.tupleof[0]; writeln(x); } --- As

tupleof seems to break encapsulation

2020-09-04 Thread 60rntogo via Digitalmars-d-learn
Consider the following code. foo.d --- module foo; struct Foo { private int i; } --- main.d --- void main() { import std.stdio; import foo; auto x = Foo(); writeln(x); // ++x.i; ++x.tupleof[0]; writeln(x); } --- As expected, the commented line does not compile. If I uncomment