`restricted` member variables

Max Samukha maxsamukha at gmail.com
Tue Jun 21 08:37:55 UTC 2022


On Monday, 20 June 2022 at 11:04:16 UTC, Mike Parker wrote:
> ```d
> class E
> {
>    restricted int _y;
>    restricted(_y) void y(int newY) { _y = newY; }
> }
> ```

The "right" way would be to hide the variable in the function's 
scope. We can hide static variables in this way, but not instance 
ones.

class E
{
   void(int newY) {
     this int y; // 'this' as storage class will likely be 
grammatically ambiguous
     newY = y;
   }
}

However, this will only work because currently it is impossible 
to access variables from the outside at all. If it's changed, the 
fundamental problem - 'private' not being scope-level - will 
return.

I am actually against any changes to the current situation. 
Module-level private is *designed* to break encapsulation, so 
breaking the invariants by module-level functions is expected.




More information about the Digitalmars-d mailing list