Why do private member variables behaved like protected in the same module when creating deriving class?
Walter Bright
newshound2 at digitalmars.com
Sat Oct 27 06:36:08 UTC 2018
On 10/26/2018 12:45 PM, David Gileadi wrote:
> It certainly is deliberate, though.
Just to confirm, yes it is deliberate.
> I believe it may have been inspired by C++'s
> "friend" declarations.
That is correct, as well. C++ friend is a hackish thing, with consequences in
appearance, name lookup and scope. Being able to declare a "friend" that is
somewhere in some other file runs against notions of encapsulation.
Java's notion of one class per module is a bit too restrictive, as one may
desire a set of closely interrelated classes that encapsulate a concept, and
those should go into a module.
C++ files tend to be accumulations of lots of stuff, often unrelated.
Translations of C++ code to D (such as dmd is) reflect that as well. Phobos
suffers from that, too, it's hard to break away from it.
D modules should reflect a more encapsulated approach, which suggests an
idiomatic D program should consist of a lot more, and smaller, modules than a
typical C/C++ organization.
---
I spent a lot of time learning programming in the 80's on floppy disks. Files
took a long time to look up and load, so one tended to organize a program as a
smaller number of larger files. Such were faster to browse and faster to
compile. These effects are insignificant today, but old habits linger.
More information about the Digitalmars-d
mailing list