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

Ali Çehreli acehreli at yahoo.com
Fri Jun 3 06:17:57 UTC 2022


On 6/2/22 22:34, forkit wrote:

 > That's so sad.

I don't feel sad at all. I stopped my response after seeing Mike's. But 
I will add that I am surprised that this issue comes up from time to time.

Have you ever been bitten by the fact that you forgot to mark a member 
private and that was a cause of some kind of trouble? (I don't think 
so.) I can't believe other programmers would use that should-be-private 
member and started abusing it.

Note that for it to be a cause of trouble, it would have been abused, 
not used. From that point of view, if others found the member useful, it 
actually means that it was a mistake to mark it private, right? Contrary 
to the other case, I do have examples of this sort though: D runtime 
used to mark GC stats private and people had to copy/paste that private 
struct to their code and access GC stats. (Real story.) See? private was 
wrong there. There are other cases where Phobos marks features private 
and I can't use them easily.

Truly private members are not needed and as Mike explained, they don't 
exist anyway. I obviously agree with the language preventing me from 
making mistakes but in the private case, it would merely be reducing 
usability. I don't want that.

D's view on private was strange to me at first but now I see that what I 
was accustomed to was wrong. I was using a feature without thinking 
about it. I find this sort of usability of D... very useful... :)

Ali



More information about the Digitalmars-d mailing list