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

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Jun 8 21:03:21 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.

Friend functions are useful when you want tight encapsulation 
without performance issues. It can help reducing the exposed 
public API to a minimum.

It can also be useful for concurrency, to make the write-api 
nonpublic etc.

It is useful for restricting the creation of objects.

And you get an explicit list.

I like it.

But there is no reason for D to become like C++. D should focus 
on simplicity and ease of use.




More information about the Digitalmars-d mailing list