Adding a new design constraint to D

Max Samukha maxsamukha at gmail.com
Sun Jun 19 06:18:44 UTC 2022


On Saturday, 18 June 2022 at 21:13:07 UTC, deadalnix wrote:
> On Saturday, 18 June 2022 at 18:02:08 UTC, Max Samukha wrote:
>> On Saturday, 18 June 2022 at 08:04:55 UTC, FeepingCreature 
>> wrote:
>>
>>> a function in a module is "on the same level" as a method in 
>>> the class.
>>
>> If it is on the same level, then I would expect 'foo' below to 
>> lock the mutex and run the invariant check:
>>
>> ```d
>> synchronized class C
>> {
>>     private int x;
>>     private int y = 1;
>>
>>     invariant() { assert(y == x + 1); }
>> }
>>
>> void foo(C c, int x)
>> {
>>     c.x = x;
>>     c.y = x + 1;
>> }
>> ```
>
> If the argument is that synchronized and invariant are messed 
> up, yes.

The argument is that those imply that encapsulation is on the 
class level while 'private' used to enforce the encapsulation is 
on the module level, which makes the design inconsistent. If 
people argue that there is no "correct" level of encapsulation 
(which I agree with), then 'synchronized/invariant' should align 
with that view.


More information about the Digitalmars-d mailing list