On Thursday, 25 January 2024 at 15:03:41 UTC, Max Samukha wrote:
On Monday, 22 January 2024 at 23:28:40 UTC, Jonathan M Davis
wrote:
Of course, ultimately, different programmers have different
preferences, and none of us are going to be happy about
everything in any language.
It's not only about preferences. The feature is inconsistent
with how 'invariant' and 'synchronized' are specified. They
imply class-instance-level private, while the language dictates
module-level. Consider:
```
synchronized class C
{
private int x;
private int y;
invariant () { assert (x == y); }
}
void foo(C c)
{
// mutate c
}
```
With module-level private, 'foo' is part of C's public
interface, but it neither locks on c, nor runs the invariant
checks. I personally have no idea how to fix that sensibly
except by ditching class invariant/synchronized entirely.
This is the only valid reason for introducing class-private
that's ever been put forth in this forum. I saw someone else post
a similar argument around class invariants awhile back as well
and it completely changed my mind on the issue.