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

forkit forkit at gmail.com
Fri Jun 3 22:50:06 UTC 2022


On Friday, 3 June 2022 at 15:41:04 UTC, Mike Parker wrote:
> On Friday, 3 June 2022 at 12:13:47 UTC, forkit wrote:
>
>>
>> Practically speaking, anyone that uses a class in D, must be 
>> put it in its own module - no exceptions.
>
> That's just nonsense.

How is it nonsense? I don't get it.

If you want the compiler to statically ensure there are no unsafe 
mutations (from other code within the same module) on the 
encapsulated represenation of a class, then you have no choice 
(apart from *manually* inspecting and verifying all the code in 
the module).

You cannot get this static ensurance from the compiler otherwise.

The aim of class abstraction is to support encapsulation and 
local reasoning. The best way to achieve this aim in D, is 
one-class-per-file.

It's nonsense to suggest that this is nonsense. It's just fact.

I do not see why their would be such a strong objection to giving 
the programmer an alternative approach. That seems 'ideological' 
to me.



More information about the Digitalmars-d mailing list