[swift-evolution] Keyword for protocol conformance

Xiaodi Wu xiaodi.wu at gmail.com
Mon Aug 22 19:15:41 CDT 2016


On Mon, Aug 22, 2016 at 7:02 PM, Charles Srstka <cocoadev at charlessoft.com>
wrote:

> On Aug 22, 2016, at 6:33 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> >
> > That's a good point. Since you're proposing an optional keyword, though,
> aren't you describing a linter functionality?
>
> If the optionality of the keyword bothers you, there are multiple ways to
> do it:
>
> Solution #1: Optional keyword.
>
> protocol P {
>         func giveUpTheFunc()
> }
>
> struct S: P {
>         implement func giveUpTheFunc()
> }
>
> Solution #2: Required keyword, but with a manual override for protocols
> that need to be retroactive.
>
> protocol P {
>         @retro func giveUpTheFunc()
> }
>
> struct S {
>         func giveUpTheFunc()
> }
>
> extension S: P {}
>
> Solution #3: No keyword, but extensions that conform to protocols can’t
> have anything other than protocol conformances unless they’re private.
>
> protocol P {
>         func giveUpTheFunc()
> }
>
> struct S {}
>
> extension S: P {
>         func giveUpTheFunc() {}
>         func tearTheRoofOffTheSucker() {} // error!
> }
>
> but this is okay:
>
> extension S: P {
>         func giveUpTheFunc() {
>                 tearTheRoofOffTheSucker()
>         }
>
>         private func tearTheRoofOffTheSucker() {} // works :-)
> }
>
> There are definitely a range of ways to make protocol conformance more
> explicit. Which one is the best, I’m not sure, but we could probably flesh
> out the pros and cons of these, as well as any other options that I haven’t
> thought of, with some discussion.
>
> Charles
>


Sure, I too am not convinced we've exhausted all the design possibilities.
Here are some previous related threads (including one launched by a core
team member):

https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/005380.html

https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160229/011792.html
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160425/015920.html

Somewhat related, but definitely a different topic:

https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160516/018286.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160822/d63d079b/attachment.html>


More information about the swift-evolution mailing list