[swift-evolution] [Review] SE-0159: Fix Private Access Levels

Tino Heth 2th at gmx.de
Mon Mar 27 06:48:25 CDT 2017

> I am now absolutely thrilled to create a filter to Mark As Read anything else arising from this thread. Good luck.

That might be a good idea — after more than 200 messages, and a quite circular discussion with an unhealthy amount of ignorance for the opposing side ;-).

To fight the latter, I just tried to take the position that "new private" is really important, and this imho leads to interesting consequences...
This access modifier really doesn't solve a problem, like "let" does (unless the problem you want to solve is having a language with private access).
Have a look at this:

public struct SeperateConcerns {
	private var foo: Int = 0
	public mutating func updateFoo(_ value: Int) {
		print("The only allowed way to change foo was invoked")
		foo = value

	private var bar: Int = 0
	public mutating func updateBar(_ value: Int) {
		print("The only allowed way to change bar was invoked")
		bar = value

	private var foobar: Int = 0
	public mutating func updateFoobar(_ value: Int) {
		print("The only allowed way to change foobar was invoked")
		foobar = value

You can protect foo from being changed by code in other files, and from extensions in the same file — and if the latter is a concern, there should also be a way to limit access to foo to specific function in scope.
Afaik, somebody proposed "partial" type declarations, but without them, the meaning of private is rather arbitrary, and the feature is only useful for a tiny special case.
If we had partial types, the situation would be different, and if would be possible to declare extensions inside a partial declaration of another type, we could even remove fileprivate without an replacement (I guess I should write a separate mail for this thought…)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170327/103a9474/attachment.html>

More information about the swift-evolution mailing list