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

bauss jj_1337 at live.dk
Fri Jun 3 10:23:40 UTC 2022


On Friday, 3 June 2022 at 10:20:08 UTC, bauss wrote:
> On Friday, 3 June 2022 at 09:02:17 UTC, forkit wrote:
>> On Friday, 3 June 2022 at 08:53:08 UTC, forkit wrote:
>>>
>>
>> class myClass
>> {
>>     _really_private string _ID;
>> }
>
> Perhaps something like:
>
> ```
> class Foo
> {
>     private class string _id; // Private to the class
> }
> ```
>
> ```
> class Foo
> {
>     private module string _id; // Private to the module
>     private int _number; // Same as "private module" since 
> that's the default
> }
> ```
>
> Of course an equivalent to structs "private struct" could be 
> added as well.

To add onto this:

This also has the advantage of having no breaking-changes, since 
old code will work just the same, but new code can leverage the 
control of what is private and to what.

There's no reason to change the default behavior of private, BUT 
having the ability to change the behavior when necessary is nice.

Some of D's decisions are far too black and white and forgot that 
there are nuances to programming.


More information about the Digitalmars-d mailing list