[swift-evolution] Simplifying Access Using 'Hidden'

Joanna Carter joanna at carterconsulting.org.uk
Mon Feb 13 10:10:18 CST 2017


Le 13/02/2017 à 15:15, Adrian Zubarev via swift-evolution a écrit : 

>  –1 
> 
> I won’t even try to be constructive on this one. It simply makes me 
> tired of all this access modifier mess. |open|, |closed|, |public|, 
> |internal|, now |hidden|, |fileprivate|, |directoryprivate|, 
> |moduleprivate|, |private|, I might even forget some of the proposed 
> access modifiers. 
> 
> Instead of adding new stuff that explodes the complexity we should put 
> our energy and fix existing issues, like the inconsistent |open| for 
> example. 

I would also say that access modifiers do seem to be be somewhat messy. 

I have never liked the idea of fileprivate ; this is the equivalent of Delphi's private scope, to which they then added strict private for class only scope. That was a similar mess. 

I am still not sure why we can't have the good old-fashioned visibilities of private, protected and public for classes. They have worked well for years and I feel we are changing things for change's sake. 

For all types other than classes, where inheritance is a feature, we have private, internal and public. 

For classes, we should definitely add protected ; I find internal just too exposing for stuff to be used exclusively by derived classes. 

But, I believe one of the motives behind fileprivate was to satisfy the need for extensions to a type to access private members. 

Just to put in my 2¢ worth, the only extra scope I would suggest could be named "extensible" and would allow anything so marked to be visible only as far as extensions ; the difference being that such extensions could then be placed in separate files. 

So, private, protected (class only), internal, public and extensible. 

Or is that too revolutionary ? 

Joanna 


More information about the swift-evolution mailing list