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

Dom Disc dominikus at scherkl.de
Tue Jun 7 07:56:30 UTC 2022


On Tuesday, 7 June 2022 at 07:23:27 UTC, zjh wrote:
> adding `class encapsulation` is to make up for the deficiency.

There is no deficiency. What we have is already capable of doing 
what is needed. @private would only add a new way to do the same 
in a sightly different (and worse) way. Just because that 
different way is more like C++ (and less like Java or other 
languages) is not enough benefit to compensate for the increase 
in mental burden.

And no, ignoring new features if you don't need them is _not_ 
working, as often you need to read or even work with code written 
by others. So you need to understand all features they use and 
cope with different styles if there is more than one way to do a 
thing. So it is always better to have only one way to do 
something, even if that doesn't please everybody.

Think of it like coding style guides: you may not like them 
because you would prefer a different style, but they increase the 
readability by large, so learn to live with them!


More information about the Digitalmars-d mailing list