[swift-evolution] private(call) and internal(call)

Félix Cloutier felixcca at yahoo.ca
Tue Jan 12 11:34:03 CST 2016


Are you allowed to call `super.functionMarkedPrivateCall()`?

Félix

> Le 12 janv. 2016 à 11:58:21, Félix Cloutier via swift-evolution <swift-evolution at swift.org> a écrit :
> 
>> Le 12 janv. 2016 à 02:11:07, cocoadev at charlessoft.com a écrit :
>> 
>> Unless we are talking about someone hacking their way in via C or assembler or something, no, they don't have the means to do so. And if we *are* talking about hacking, then that's impossible to prevent, anyway, if someone is *really* determined. I mean, even if the stupid thing is inlined, you could still disassemble the thing and copy-and-paste out the relevant part. Making things 100% bulletproof is not the goal, and if it were, we would have been publishing every single API, private and public, in Objective-C, since in that language it was staggeringly easy, even for a relative neophyte, to find and call private methods on pretty much anything. Despite that, we still found it useful to hide things in private headers and implementation files, which suggests that access control does have a use beyond the linker level after all.
> 
> class A {
> 	private(call) func logicYouShouldImplementButNotCall() {
> 	}
> }
> 
> /* other module */ class B {
> 	private(call) override func logicYouShouldImplementButNotCall() {
> 		iActuallyWantToCallItWhyWontYouLetMeDoIt()
> 	}
> 	
> 	func iActuallyWantToCallItWhyWontYouLetMeDoIt() {
> 		/* snip */
> 	}
> }
> 
>>> The only un-abusable justification for the feature is to document that
>>> a symbol shouldn't be used directly, hence the suggestion to use
>>> documentation features to achieve that goal.
>> 
>> It has multiple goals:
>> 
>> 1) To document that it shouldn't be called directly
>> 
>> 2) To keep it from being called accidentally via code completion
>> 
>> 3) To make it enough of a PITA to call that people will be more likely to just do things the right way.
> 
> I'm not in favor of complexifying access control for the sake of documentation. The first two goals can be implemented with just a little more collaboration between tools and documentation and you can get 90% of the way there for the third one as well.
> 
> Félix
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list