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

Ali Çehreli acehreli at yahoo.com
Sat Jun 4 07:04:35 UTC 2022


On 6/3/22 22:07, forkit wrote:
 > On Saturday, 4 June 2022 at 01:41:52 UTC, Mike Parker wrote:
 >>
 >> ....
 >> It would require adding a new protection keyword to the language. The
 >> general policy for that is that there must be a strong benefit. Given
 >> that we already have a way to achieve the same goal (putting classes
 >> in their own modules), then the benefit of such a keyword is extremely
 >> weak.
 >
 > Well, I've never encounted as much resistance to change, as what occurs
 > when someone brings this topic up in a discussion.

I think the reason is there is no strong argument for one way or the 
other. There are two options:

a) 'private' means "private to the class", which necessitates the 
equivalent of the keyword 'friend'. This option is what C++ chose.

b) 'private' means "private to the module", which frees 'friend' as a 
user symbol. This option is what D chose.

 > I really do think there is idealogical resistance to such a change, and
 > it's this that brings about these strong reactions.

Since D came after C++, it is clear that option b was seen to be 
superior. Let's hear arguments why option a is better than b.

 > Cause D has plenty of completely useless attributes. I don't think
 > another one is going to make much difference.

It will make N+1.

 > In the meantime, if a D programmer wants

Ah!

 > static, compile time
 > verification that that the encapsulation of a class

Ah!

 > is not broken, then
 > they MUST put that class in a separate module (one module per class).

Where did "wants" and "encapsulation of class" come from? Why would a D 
programmer not "need" "encapsulation of module"? Let's hear arguments 
about why one is better than the other. Which text book are we following?

Why are you stopping at class level? Why would one member function of a 
class access members that were supposed to be touched only by another 
member function? Where is that abstraction? Why don't we "want" that? Is 
it because other languages don't provide that? This whole discussion of 
encapsulation levels is arbitrary.

 > No exceptions.

I am not going to contribute to your projects. Life is too short to 
follow "core guidelines". How about actually getting things done?

Ali



More information about the Digitalmars-d mailing list