dragon-lang / dc

D Compiler
Boost Software License 1.0
8 stars 0 forks source link

private should mean private #41

Open marler8997 opened 5 years ago

marler8997 commented 5 years ago

In my opinion, private should mean private to the class/struct, not to the module. I think module ownership is a fine idea, but should be have it's own visibility.

struct Foo
{
    private int x;
    package int y;
    module int z; // ???
}

Foo foo;
foo.x; // error, x is not visible
foo.y; // ok
foo.z; // ok
wilzbach commented 5 years ago

I never considered this a big issue. On the contrary, I quite like that for testing you can introspect into the class if you want to. (though I don't have a strong feeling about this)

marler8997 commented 5 years ago

Yeah, white box testing is good and this problem of accessing private fields is a common one in any language. One idea is to have the language grant visibility to all private fields if it's inside a unittest block or version(unittest).

aliak00 commented 5 years ago

Or have a fileprivate scope or public/protected/private/package/module. Or package(this) to mean module. Or private(this) to mean "real" private and don't change the current private.