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

Mike Parker aldacron at gmail.com
Thu Jun 9 01:54:22 UTC 2022


On Thursday, 9 June 2022 at 01:04:26 UTC, forkit wrote:
> On Thursday, 9 June 2022 at 00:38:56 UTC, Mike Parker wrote:

> I have no say in this, other than these 'work arounds' that you 
> insist I follow - including the best one yet 'just don't do it'.

I explained that. Here's some code since it apparently wasn't 
clear what I meant:

```d
class Foo {
     int specialSauce;

     void onlyModifySauceHere(int newVal) {
         assert(newVal > someMin && newVal <= someMax);
         specialSauce = newVal;
     }

     void functionAddedByCluelessTeamMember() {
         specialSauce *= 100;
     }
}
```

How is this problem solved in Java? Don't do it. C++? Don't do it.

In D, if you don't want functions in the module accessing private 
class members, don't do it. There is no practical difference 
whatsoever if the offending function is above or below the 
closing brace.

> I do not have to make the case

You're the one who wants the feature, so yeah, the onus is on you 
or someone who agrees with you to convince the maintainers of the 
language that it's a feature worth having. Otherwise, it isn't 
going to happen.

You've said enough about this topic in this thread and others 
that you could have written a DIP by now. And both of us are 
repeating the same points over and over, so I'm done with it.




More information about the Digitalmars-d mailing list