Why do private member variables behaved like protected in the same module when creating deriving class?
unprotected-entity
unprotected-entity at gmail.com
Tue Oct 30 06:44:10 UTC 2018
On Tuesday, 30 October 2018 at 01:33:50 UTC, Neia Neutuladh wrote:
>
> That your request to make D's `private` work like Java, C#, and
> C++ isn't consistent because they work differently from each
> other.
>
I've already demonstrated that they all work the same:
see:
https://forum.dlang.org/post/dyfnrbjggqzianfwgvll@forum.dlang.org
And I don't want private in D to mean anything other than what it
currently means - as that would be a breaking change, that could
never be acceptable.
On the otherhand, I have see ideas/propsals presented that do not
really involve complexity, do not change what private means, but
still provides an option to the programmer to better encapsulate
their class, inside a module, from other code also in that
module. I don't think that is so bad an idea, as to be completely
dismissed.
> Do you want to make things work like C++? Then you'll need to
> add a notion of friends.
No you don't. Stuff inside a module are already friends - they
can do whatever they want to each other. Hopefully, the line the
crashes your plane, is not on line 10,001 (cause you might not
see that it's bypassing the interface of your class declared 9000
lines above it.
I don't want more friendship, I want less (inside a module that
is).
And, I am specifically referring to classes, not structs.
(although presumably it would be easy enought to accomodate a
change to both.
A such would have no effect outside of the module. So it's all
back in the control of the programmer, rather than the language.
btw. here is an interesting paper on 'friends' - well worth
reading.
> When you say "people will expect this to work like these three
> other languages" and those other languages do that thing
> differently from each other, it's hard to take your claims
> seriously.
really? when I looked at D, I expected the notion of private,
declared within a class, to be private to that class (no matter
what else is in the module).
That is what I expected. This is what C++/c#/Java does. It's a
reasonable expectation for someone looking at using D. Is it not?
(unless you intentionally try to override that - with, for
example, a friend).
In D, that overriding happens for you, automatically, within a
module, and you get no say in it... whatsoever.
And I know for a fact, that I am not the only one who expected
that private declared within a class, to mean what it means in
C++/Java/C#
So I cannot take your claim (that such expectations do not exist)
seriously.
> I exercise patience at the start, and it wears thin when people
> repeatedly ignore me.
You starting to sound like that guy that runs the linux kernel
project.. I believe he's just take time off to deal with that
attitude...
More information about the Digitalmars-d
mailing list