Extending D's support for object-oriented design with private(this)

NotYouAgain NotYouAgain at gmail.com
Sat Apr 27 09:18:31 UTC 2024


On Saturday, 27 April 2024 at 08:29:46 UTC, Arafel wrote:
> ..
> ....
> That being said, I would have very much preferred to have this 
> feature available.

It's great that this idea is attracting some support ;-)

Sadly, it's usually just those against it that voice their 
opinions.

> Another aspect not being discussed here are synchronized 
> classes...

so, it seems, at least 2 problems indentified in this discussion, 
can now be solved with private(this).

1 - It can (apparently) resolve an issue with synchronized 
classes (I' don't pretend to understand them)

2 - It can prevent private(this) members from being accessible in 
a unittest (where the unittest is outside the scope of the class 
- which is how i always do them anyway). That is, the unittest 
can be made to only be able to test the public interface now. The 
compiler itself will enforce this constraint.

I expect there are alternative solutions to both 1 and 2. But I 
expect any alternative solution would only solve one of them, and 
a different alternative solution would be needed to solve the 
other.

But private(this) can solve both ?

Wow. One solution, to multiple problems. How cool is that!



More information about the dip.ideas mailing list