July 15, 2021

On Thursday, 15 July 2021 at 18:06:26 UTC, Steven Schveighoffer wrote:

>

On 7/15/21 1:43 PM, Tejas wrote:

>

How do you write the equivalent of that in D? Is the answer still the same? Manually keep it in the same module, or is there a programmatic way of converting this to D?

Functions in the same module can access private members. Functions in the same package (or in whatever package you specify) can access package members. That is how D does "friends".

So the answer to your question depends on how the C++ code is organized.

It's always possible that something in C++ here is not translatable into D, but most likely can be redesigned (and likely better designed).

-Steve

Yes, it seems like seperating chunks of C++ code into seperate modules and using the

package(qualifiedIdentifier)

access specifier seems to be the way to go.

Was wondering if there was some wizardry that the veterans knew that would make it less difficult, but it seems this is the only way.

Thank you very much for replying!

July 15, 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

July 15, 2021
On 7/15/21 5:46 PM, Ali Çehreli wrote:

> On 7/15/21 11:24 AM, Tejas wrote:

>  > package(qualifiedIdentifier)

> Just don't do it

Ok, I said all that before realizing what you needed with transpiling C++ to D and the solution of package(qualifiedIdentifier). (And package(qualifiedIdentifier) is news to me! :) )

Ali


1 2
Next ›   Last »