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

Max Samukha maxsamukha at gmail.com
Thu Jun 9 13:05:46 UTC 2022


On Wednesday, 8 June 2022 at 20:35:30 UTC, Walter Bright wrote:
> On 6/8/2022 1:23 AM, Max Samukha wrote:
>> Why is it less of an abomination?
>
> Because "friend" classes are a mess. They can be spread all 
> over your code.
>
> Modules are physically co-located in the same file, making them 
> easy to manage.

To me, mandating a certain codebase structure is not an 
advantage. Also, you can always misuse 'package' to make a mess 
out of a D codebase.

'friend' is abominable for a different reason - it breaks 
encapsulation by exposing the entire state instead of selected 
members, and D is no different in this respect.


More information about the Digitalmars-d mailing list