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

Dom Disc dominikus at scherkl.de
Wed Jun 8 08:11:41 UTC 2022


On Wednesday, 8 June 2022 at 06:45:24 UTC, forkit wrote:
> The proof is already there - i.e. C++/Java/C# programmers, 
> already use and rely upon this feature. Imagine if those 
> languages took it away.

Ok, you don't get why I (and D) like it to not conflate things 
that don't need access to the innards of a class within the same 
file.

I on the other side don't get why you think forbidding access 
from outside of one file is _not_ encapsulation. It is. And it is 
easy to control: you put all friends in the same file, and 
nothing else. You don't have to search where all the friends may 
be implemented. And if you want something to have no access to 
the privates, just move it to some other file. Don't tell me this 
is error-prone or hard to review. It's much easier than to look 
for all friends in the whole project. I personally *hate* it if I 
should review a file and then need to look into dozends of other 
files to do this. And C++ tend to always require this. One of my 
main reasons to drop C++.
Java doesn't even allow friends or subclasses to reside within 
the same file, and nobody complains about that or claims that 
this is not encapsulation.


More information about the Digitalmars-d mailing list