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

bauss jj_1337 at live.dk
Thu Jun 9 09:47:54 UTC 2022


On Thursday, 9 June 2022 at 06:21:08 UTC, forkit wrote:
> On Thursday, 9 June 2022 at 05:52:10 UTC, rikki cattermole 
> wrote:
>> private(scope)
>>
>> Nice and simple, if you know what private and scope does, you 
>> can probably guess what it does here.
>
> It's just those brackets that bother me. Something doesn't seem 
> right with them there like that. Consider where else in the 
> language () is used, for example.
>
> btw.
>
> In swift (where they seem to have actually thought this out 
> sensibly):
>
> 'fileprivate' -> means an entity that is accessible anywhere in 
> that file.
>
> 'private' -> means an entity that cannot be accessed anywhere 
> except for the enclosing type, such as a class
>
> so here's yet another idea: - just an idea, not a proposal ;-)
>
> private -> no change. means an entity that is accessible 
> anywhere in that file.
>
> scopeprivate -> means an entity that cannot be accessed 
> anywhere except for the enclosing type, such as a class

Couldn't it be `private scope` or `scope private` then if the 
brackets bother you?

I think scopeprivate as a keyword is really long. Maybe it could 
just be `scope` and nothing else, since `scope` as it is now 
cannot be used in the same context and thus it won't conflict 
with how it currently is.

But perhaps it's better to have `hidden` then anyway since it's 
much more clear.


More information about the Digitalmars-d mailing list