Why do private member variables behaved like protected in the same module when creating deriving class?

unprotected-entity unprotected-entity at gmail.com
Mon Oct 29 23:15:58 UTC 2018


On Monday, 29 October 2018 at 15:50:56 UTC, Jonathan M Davis 
wrote:
>
> If anything, many of us have been convinced of the opposite by 
> actually using D. The way that D treats private is pratical and 
> useful, and adding a way to further restrict access to member 
> variables of classes would just be a further complication to 
> the language with little to no pratical benefit.
>
> If you don't like that, that's fine. I don't think that any of 
> use like _every_ design decision made in D, but many of us do 
> like this design decision, and plenty of folks had a negative 
> reaction to it when they initially found out. However, 
> experience tends to show that D's design decision here works 
> extremely well.
>
> - Jonathan M Davis

It's not (just) that I don't like it, it's that I don't like not 
giving the programmer the tool to better encapsulate their code 
(specifically classes) *within* a module.

Well, as Walter said in a previous post, "Being able to declare a 
"friend" that is somewhere in some other file runs against 
notions of encapsulation."

My argument is not too dissimilar.

Forcing everything in a file, to be friends with each other, runs 
against the notions of encapsulation. Sure, put the class in its 
own module. But then you lose the encapsulation property and 
convenience, of the module. So you worse off, no matter how you 
look at it, in D.

The difference between the C++ way, and the D way, is that the 
C++ way (friends) is not really encouraged - i.e. it's mostly for 
corner cases - it's not meant to be how you go about 
architecturing your software - surely.

In D however, it's exactly how you're meant to do it - it's by 
design - it's reaching out and saying, this is how you should do 
it. D seems to be proud, that you cannot encapsulate a class, 
within a module, from other code also in that module. If 
C++/C#/Java took that view, imagine the outcry.

In any case, I don't really care so much about D, but about good 
design.

And given what I've seen in phobos..well... I'm still looking for 
the 'design'.

All I see are gigantic modules full of code...that does who knows 
what to each other..cause they're all friends and can do whatever 
they like to each other, in D.



More information about the Digitalmars-d mailing list