How to create friends of a class at compile time?
Ali Çehreli
acehreli at yahoo.com
Fri Jul 16 00:46:03 UTC 2021
On 7/15/21 11:24 AM, Tejas wrote:
> it seems like seperating chunks of C++ code into seperate modules
> and using the
> ```d
> package(qualifiedIdentifier)
> ```
> access specifier seems to be the way to go.
That would be necessary if one agreed with C++'s 'private' to begin
with. In other words, one would agree that implementations inside one
source file should be protected from each other.
Through Walter Bright's experience, D does not buy into that view: It is
silly to protect implementation details of features of the same file
from each other. Personally, I fully agree! I am rarely strongly
opinionated; this topic is one of those cases. :) In hind sight, this is
one of the examples of D that thought me and improved me.
C++'s 'friend' "feature" covers up a language design mistake: It is a
mistake because a tool should be useful; C++'s 'private' protects the
programmer unnecessarily strongly from himself or herself. What a view
that causes unnecessary mental load on many programmers with the
'friend' keyword...
If you agree with all of that, then your idea of separating chunks into
separate modules becomes unnecessary work. Just don't do it and you will
miss nothing at all. You will gain a lot in the future without even
noticing it. :)
Ali
More information about the Digitalmars-d-learn
mailing list