Using closure in function scope to make "real" private class members

forkit forkit at gmail.com
Thu Jun 9 01:56:26 UTC 2022


On Friday, 3 June 2022 at 05:58:06 UTC, Mike Parker wrote:
>
> ...
> In D, given module `mymod`, you can split your aggregates into 
> individual files and make a package module:
>
> ```
> - mymod
> -- package.d
> -- classA.d
> -- classB.d
> -- freefuncs.d
> ```
>
> Then clients can still treat `mymod` as a single module, and 
> you get your ideological purity. But your problem of 
> programmers having access to the private memvers of `ClassA` if 
> they have access to `classA.d` doesn't go away. It's just been 
> moved to a different module.

Those last two lines of your response, is 'my justification'.

i.e. none of the workarounds make the problem go away.

All they do is add totally unnecessary cognitive load, to what 
should be a really simple, straightforward, design decision - I 
want this to be private to this class.

Access control decisions should not be dictated to me by D.

Access control is a decision I (the designer) have the right to 
make, and also the right to expect the compiler to enforce.

Claiming this right to be just 'ideological purity' is a nice 
distraction ;-)



More information about the Digitalmars-d mailing list