Required Reading: "How Non-Member Functions Improve Encapsulation"
rikki cattermole
rikki at cattermole.co.nz
Thu Oct 26 05:05:12 UTC 2017
On 25/10/2017 11:19 PM, Walter Bright wrote:
> for core D devs.
>
> "How Non-Member Functions Improve Encapsulation" by Scott Meyers
>
> http://www.drdobbs.com/cpp/how-non-member-functions-improve-encapsu/184401197
>
>
> Note that I'm as guilty as anyone for not understanding or following
> these guidelines. I expect we can do much better.
UFCS kills off a good part of those arguments, but point still stands.
```D
struct Point {
private int[2] d;
this(int x, int y) {
d[0] = x;
d[1] = y;
}
@property {
ref int x() { return d[0]; }
ref int y() { return d[1]; }
}
}
void main() {
Point p = Point(1, 3);
p.y = 2;
}
```
Hehe ;)
More information about the Digitalmars-d
mailing list