[swift-evolution] A Comprehensive Rethink of Access Levels in Swift

Rien Rien at Balancingrock.nl
Sun Feb 26 11:53:29 CST 2017

Just joking of course (???)

Exposure levels: World, Module, File, Type (= [ W | M | F | T ])
Access control: Read, Write, Override, Inheritable (= [ R | W | O | I ])

let api = Access(w, [r, -w, -o, -i]) // Access must always be statically resolved
let mod = Access(m, [r, w, -o, i])
let cust = Access(api, mod, (f, [r, -w, o, i]), (t, [r, w, o, i]))

access(cust) var a: Int

Ok, joking besides…

I think the above suggestion is madness. Sure it would work and it is not even close to the worst possible solution.

In effect what I see people suggesting is exactly the above, only differently phrased:

fileprivate = access((w, [-r, -w, -o, -i]), (m, [-r, -w, -o, -i]), (f, [r, w, o, i]), (t, [r, w, o, i]) 
public private(set) = access((w, [r, -w, -o, -i]), (m, [r, -w, -o, -i]), (f, [r, -w, -o , i]), (t, [r, w, o, i])
open = …
final = ...

etc, you get the drift
What I am trying to show in this example is the complexity of trying to implement the full set of possible controls by introducing keywords (or keyword combinations!) for each possible combination.

I like simplicity. The TO suggestion would suit me just fine.

But there is a tip over point: when we get too many keywords then it becomes simpler to dump the keyword approach and go for the full Monty.

IMO in Swift 3 we are already dangerously close to the tip-over point.


Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl

More information about the swift-evolution mailing list