{"id":17657,"date":"2017-04-06T14:35:23","date_gmt":"2017-04-06T18:35:23","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=17657"},"modified":"2020-04-21T14:20:29","modified_gmt":"2020-04-21T18:20:29","slug":"thoughts-on-swift-access-control","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/04\/06\/thoughts-on-swift-access-control\/","title":{"rendered":"Thoughts on Swift Access Control"},"content":{"rendered":"<p><a href=\"http:\/\/www.jessesquires.com\/thoughts-on-swift-access-control\/\">Jesse Squires<\/a> (<a href=\"https:\/\/twitter.com\/jesse_squires\/status\/849791889981161472\">tweet<\/a>):<\/p>\n<blockquote cite=\"http:\/\/www.jessesquires.com\/thoughts-on-swift-access-control\/\"><p>The proposal <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0025-scoped-access-level.md\">SE-0025<\/a>: <em>Scoped Access Level<\/em> was <a href=\"https:\/\/lists.swift.org\/pipermail\/swift-evolution-announce\/2016-February\/000049.html\">reviewed<\/a>, <a href=\"https:\/\/lists.swift.org\/pipermail\/swift-evolution-announce\/2016-March\/000063.html\">revised<\/a>, and finally <a href=\"https:\/\/lists.swift.org\/pipermail\/swift-evolution\/Week-of-Mon-20160328\/014008.html\">accepted<\/a> for Swift 3. This proposal changed the meaning of <code>private<\/code> to restrict access to an entity to within the current scope or declaration, and preserved the former meaning with a new keyword, <code>fileprivate<\/code>. The hypothesis at the time was that the new (and somewhat intentionally ugly) <code>fileprivate<\/code> keyword would rarely be used, thus abiding by Swift&rsquo;s design philosophy of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Progressive_disclosure\">progressive disclosure<\/a>. Little did we know that this would <em>not<\/em> be true in practice.<\/p><p>[&#8230;]<\/p><p>After <strong>three<\/strong> controversial <a href=\"https:\/\/lists.swift.org\/pipermail\/swift-evolution-announce\/2016-July\/000249.html\">review periods<\/a> and revisions, proposal <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0117-non-public-subclassable-by-default.md\">SE-0117<\/a>: <em>Allow distinguishing between public access and public overridability<\/em> was <a href=\"https:\/\/lists.swift.org\/pipermail\/swift-evolution-announce\/2016-July\/000268.html\">accepted<\/a> for Swift 3. The proposal introduced a new access level called <code>open<\/code> and changed the definition of <code>public<\/code> in some contexts.<\/p><p>[&#8230;]<\/p><p>Most recently, proposal <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0159-fix-private-access-levels.md\">SE-0159<\/a>: <em>Fix Private Access Levels<\/em> was put forward to simply revert the changes of <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0025-scoped-access-level.md\">SE-0025<\/a>. That is, remove <code>fileprivate<\/code> and restore the original (Swift 1 and 2) semantics of <code>private<\/code>. [&#8230;] The new <code>private<\/code> essentially broke Swift&rsquo;s extension-oriented style, as <code>private<\/code> members of a type were no longer accessible from an <code>extension<\/code> on that type, even if the <code>extension<\/code> was declared in the same file. The proposal was <a href=\"https:\/\/lists.swift.org\/pipermail\/swift-evolution-announce\/2017-March\/000332.html\">reviewed<\/a> with as much controversy and ferver as SE-0025 itself. [&#8230;] SE-0159 was <a href=\"https:\/\/lists.swift.org\/pipermail\/swift-evolution-announce\/2017-April\/000337.html\">rejected<\/a>, leaving the state of access control unaltered.<\/p><p>[&#8230;]<\/p><p>The Core Team&rsquo;s proposal that Doug outlines above is a good compromise. Before I could publish this post, David Hart opened a <a href=\"https:\/\/github.com\/apple\/swift-evolution\/pull\/668\/files\">pull request<\/a> with a draft proposal titled <em>Type-based Private Access Level<\/em> for this. I hope it gets accepted and implemented. [&#8230;] The benefits of a &ldquo;partly lexical and partly type-based&rdquo; access control that Doug explains are clear, and I think the outweigh the drawbacks.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Jesse Squires (tweet): The proposal SE-0025: Scoped Access Level was reviewed, revised, and finally accepted for Swift 3. This proposal changed the meaning of private to restrict access to an entity to within the current scope or declaration, and preserved the former meaning with a new keyword, fileprivate. The hypothesis at the time was that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2020-04-21T18:20:31Z","apple_news_api_id":"b80f0e73-dcf4-4686-9aaa-0d506c85d84b","apple_news_api_modified_at":"2020-04-21T18:20:31Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AuA8Oc9z0Roaaqg1QbIXYSw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[46,71,901],"class_list":["post-17657","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=17657"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17657\/revisions"}],"predecessor-version":[{"id":28751,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17657\/revisions\/28751"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=17657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=17657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=17657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}