[swift-evolution] [swift-evolution-announce] [Review] SE-0117: Default classes to be non-subclassable publicly
Matthew Johnson
matthew at anandabits.com
Wed Jul 6 16:47:34 CDT 2016
> On Jul 6, 2016, at 4:36 PM, Scott James Remnant via swift-evolution <swift-evolution at swift.org> wrote:
>
>
>> On Jul 6, 2016, at 2:13 PM, Leonardo Pessoa <me at lmpessoa.com <mailto:me at lmpessoa.com>> wrote:
>>
>> You can also try and simplify your outlines reducing X.c and X.d to a
>> single entry as it is the same rule applied to two different elements
>> of the language. Using one single keyword (such as in 'open') would
>> make it clearer and that is why I prefer to have only one keyword.
>>
>
> I didn’t simply the outlines precisely because the proposal suggests two keywords.
>
> One keyword does solve this problem, but not the problem of conflation of finality and access control.
> You end up with this matrix:
>
> access | can override | final
> -------------+--------------+-------
> open | yes | Error - “class cannot be open and final”
Of course this produces a compile error. Open means “can subclass” which directly contradicts final.
> public | no | Error - “public class is already final by default”
This is not true. Public classes will *not* be “final by default”. It *will* be possible to subclass them within their declaring module. If they need to be final they will still need to be marked as such.
With that in mind, the your “can override” column (do you really mean “can subclass” here?) is also not correct. The correct answer is “yes, within the module”. The fundamental difference for this row is that there are some scopes which can *see* the type without the ability to subclass it. There is no problem with this, it is *exactly* what we want.
The purpose of this proposal is precisely to give library authors the ability to have more fine grained control over what capabilities their library exposes to users.
> internal | yes | final
> fileprivate | yes | final
> private | yes | final
>
> This is way more confusing than the current language:
>
> access | can override | final
> -------------+--------------+-------
> public | yes | final
> internal | yes | final
> fileprivate | yes | final
> private | yes | final
>
> I strongly favor a programming language that doesn’t introduce compiler errors to solve problems that could be solved by cleaner syntax.
>
> Since it’s already necessary to place the `public` keyword in front of every class, method, property, or subscript that you intend to make public, the developer is already thinking about the public API. Typing `public final` instead of `public` is an extra keyword, it’s not an extra cognitive burden since that cognition is already taking place.
As you can see from the points above, `public final` is something very different than both `public` and `public subclass able` (or `open`) under the current proposal. It is not a question of cleaner syntax. It is a question of whether we want to give library authors more fine grained control.
-Matthew
>
> Scott
>
> _______________________________________________
> 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/20160706/75f32e26/attachment.html>
More information about the swift-evolution
mailing list