[swift-evolution] Suggestion to clean up the mess around access modifiers

Adrian Zubarev adrian.zubarev at devandartist.com
Tue Feb 21 08:44:41 CST 2017


Updated with a third suggestion which makes it more clear that ‘closed’ by default simply does not work without allowing the existence of closed protocols.

Formated version: https://gist.github.com/DevAndArtist/ae33145aa71a6212981b54c307e7c1e6/edit

Suggestion 1	Suggestion 2	Suggestion 3	Swift 3	Implication of #3
public	open	open public	open	open
closed public	public	public	public	public
fixed public			 		
final public	closed	final public	final public	final public
internal	internal	internal	internal	internal
final internal	final internal	final internal	final internal	final internal
private	private	private	fileprivate	private
final private	final private	final private	final fileprivate	final private
scoped	scoped	scoped	private	scoped
open is no more an exclusive access modifier, which shouldn’t exist in the first place, because of the mentioned exclusivity. That’s what attributes are meant for.
Allowing closed public protocols seems straightforward for Suggestion 1.
First suggestion aligns the closed attribute very well with final and its purpose becomes crystal clear.
scoped is a straw_hat_name from the on going discussions, you can replace it with something better.
fixed public is from Matthew’s discussion thread.
Third suggestion makes open as an attribute, however this is a breaking change for all other types different form classes, because currently protocols have open semantics, and value types might get subtypes one day, which makes them closed by today’s standards. The default in the first suggestion is alway open, compared to the third suggestion, which is closed.
The implication of the third suggestion is the necessary fix for protocols: open/public protocol (shown in the last row).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170221/e1956ad7/attachment.html>


More information about the swift-evolution mailing list