[swift-evolution] access control

David Waite david at alkaline-solutions.com
Sat Jan 23 17:13:36 CST 2016

> On Jan 23, 2016, at 3:14 PM, Ilya Belenkiy via swift-evolution <swift-evolution at swift.org> wrote:
>>  With a file based access control, the only way to tell if an API is really private or can be safely used anywhere in the same file is to read the comments / source code. And it’s much easier to miss in maintenance, debugging, or code reviews. The only way to make it obvious in the current model is to adopt a convention like _ in front of methods.

Within the same file, I would expect a member of my team writing code has the domain knowledge to do so correctly.

Is the primary use case meant for files which have grown too large/complex for the authors to be expected to comprehend the type state invariance of the code they are currently working on?

Or is the thought that developers may add code to the file to get access to private api (and implicit action), while they would not be willing to edit the access levels to do so otherwise (an explicit action)? This sounds like a process issue within a team, as access control flags will not necessarily restrict the process of modifying the code in certain ways for people who are already tasked with such without such external process/ramifications in place.

>> There's nothing about extending a class that ought to raise a red flag in Swift, because it's perfectly legit to do so and use only the class' public APIs.
> Unless the programmer extends a class in the same file. Then he can call anything marked private, and it’s impossible to tell without reading the code whether it violates the class invariants. There is no way to express this in Swift today. My proposal for local / scoped access control would solve this.

There is nothing about someone editing that file to change a “local" access modifier to “internal" which will raise a red flag with Swift. Is this something that you plan to detect and block via a SCM commit hook/code review product?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160123/98d642a9/attachment.html>

More information about the swift-evolution mailing list