<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hello Vladimir,</div><div class=""><br class=""></div><div class="">Going back to the original suggestion:</div><div class=""><br class=""></div><div class=""><div class=""><i class="">4.1 Different implementation for different protocols</i></div><div class=""><i class="">class Foo : ProtocolA, ProtocolB {</i></div><div class=""><i class="">&nbsp; &nbsp;implement(ProtocolA) func foo() {...}</i></div><div class=""><i class="">&nbsp; &nbsp;implement(ProtocolB) func foo() {...}</i></div><div class=""><i class="">}</i></div><div class=""><i class="">class Foo : ProtocolA, ProtocolB {</i></div><div class=""><i class="">&nbsp; &nbsp;implement ProtocolA {</i></div><div class=""><i class="">&nbsp; <span class="Apple-tab-span" style="white-space:pre">        </span>func foo() {...}</i></div><div class=""><i class="">&nbsp; &nbsp;}</i></div><div class=""><i class="">&nbsp; &nbsp;implement ProtocolB {</i></div><div class=""><i class="">&nbsp; <span class="Apple-tab-span" style="white-space:pre">        </span>func foo() {...}</i></div><div class=""><i class="">&nbsp; &nbsp;}</i></div><div class=""><i class="">}</i></div><div class=""><br class=""></div>I would rather solve this by implementing the conformance of Foo to either protocol in its own extension:</div><div class=""><br class=""></div><div class="">class Foo {}</div><div class=""><br class=""></div><div class="">extension Foo: ProtocolA {</div><div class="">&nbsp;func foo()</div><div class="">}</div><div class=""><br class=""></div><div class="">extension Foo: ProtocolB {</div><div class="">&nbsp;func foo()</div><div class="">}</div><div class=""><br class=""></div><div class="">This way the extra keyword is not necessary.</div><div class="">However it does make it necessary to be able to select the exact foo() an API user would want.</div><div class="">The API user has that knowledge and can select if via: (Foo as! ProtocolA).foo()</div><div class=""><br class=""></div><div class="">Or via a convenience dot-contruction: Foo.ProtocolA.foo()</div><div class=""><br class=""></div><div class="">I think that my suggestion may be more work, but it feels to me as if it is more in line with the general swift-phylosophy.&nbsp;</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Rien.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class="">On 23 Sep 2016, at 15:08, Vladimir.S &lt;<a href="mailto:svabox@gmail.com" class="">svabox@gmail.com</a>&gt; wrote:<br class=""><br class="">On 23.09.2016 15:10, Rien wrote:<br class=""><blockquote type="cite" class="">Note: Second attempt, first mail was rejected ?<br class=""><br class="">That is correct Vladimir, at the point of writing an API you never know who will end up using it in which way.<br class="">Hence the decision which flavour (of a function) to call should not be made by the coder writing the API but by the coder using the API.<br class="">And that coder cannot claim not to know which flavour he wants.<br class="">Hence including the ‘override’ keyword is unnecessary. However having the ability to specifying which flavour must be called is necessary. And this ability is easy to&nbsp;accommodate within the current language rules. (casting or possibly having a dot-notation for this purpose)<br class=""></blockquote><br class="">Sorry, I'm not sure I fully understand.. I replied to Maximilian's suggestion to use `conform` keyword if there is no default implementation for implemented protocol&nbsp;requirement and use `override` if there is such default implementation for the requirement. So, I show that we can't accept such solution as it leads to such kind of&nbsp;dependency when some other's code depends on your local code. I.e. if you add default implementations for protocol defined in 3rd party code - you can break compilation&nbsp;of that code and this should not happen(see my example in previous message).<br class=""><br class="">As for requirement for any keyword to mark protocol implementation method/prop in type - there were a lot of description in the thread why we need this and what kind of&nbsp;problem this could solve and prevent hard-to-find bugs. Also please look into initial problem of this thread.<br class=""><br class=""><blockquote type="cite" class=""><br class="">Regards,<br class="">Rien.<br class=""><br class=""><blockquote type="cite" class="">On 23 Sep 2016, at 12:47, Vladimir.S via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">On 23.09.2016 11:05, Maximilian Hünenberger wrote:<br class=""><blockquote type="cite" class="">I'd also say that one or two keywords are superior than the protocol naming<br class="">approach in terms of implementation simplicity (for the core team).<br class=""><br class="">My suggestions:<br class=""><br class="">Either "conform" or "implement" should be a required keyword for all<br class="">properties/functions which implement a protocol (also in protocol extensions)<br class=""><br class=""></blockquote><br class=""><blockquote type="cite" class="">"override" should be used if a default implementation or a member of a<br class="">superclass is overridden.<br class=""></blockquote><br class="">Maximilian, again, you *do not know* if the conformed protocol, that has no default implementations *at the moment of your code writing* will or will not have default&nbsp;implementations at the *moment of compilation*.<br class="">Consider this scenario:<br class=""><br class="">Step 1. You got 3rd party source file for your project, and you don't want/have no rights to change it, probably it is shared source used also in other projects, that code&nbsp;contains:<br class=""><br class="">protocol A { func foo() }<br class=""><br class="">class B : A {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>conform func foo() {...}<br class="">}<br class=""><br class="">all is OK with this code, no default implementation, B.foo marked with `conform`.<br class=""><br class="">Step 2. In your project in some of your files you decided to add default implementation of protocol A:<br class=""><br class="">extension A {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>implement func foo() {...}<br class="">}<br class=""><br class="">Now, your project will not compile - B.foo() must me marked with 'override' as protocol `A` has default implementation of foo().<br class="">If you change `conform` to `override` in 3rd party source file, it will not compile in some other project where no default implementation defined for `A` protocol.<br class=""><br class="">That is *why* I believe the `override` as requirement as marker for protocol implementation method/prop is the best solution. See, in case `override` will be required, the&nbsp;initial source file will be like this:<br class=""><br class="">protocol A { func foo() }<br class=""><br class="">class B : A {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>override func foo() {...} // implementation<br class="">}<br class=""><br class="">and it will compile ok : if A has default implementation and if A has no default implementation.<br class=""><br class="">So, after you added default implementation in your project - no changes should be made to that 3rd party source file.<br class=""><br class=""><br class=""><blockquote type="cite" class=""><br class="">If you are overriding a default implementation of a protocol "conform" /<br class="">"implement" is also required.<br class=""><br class="">// Retroactive conformance (old behavior) but only in extensions<br class="">extension Foo: @retroactive Baz {<br class="">&nbsp; // only some members of Baz are implemented here (they need the keywords)<br class="">&nbsp; // the other members outside the extension don't need any additional<br class="">keywords<br class="">&nbsp; // note: you can use "@retroactive" and "conform" in conjunction<br class="">}<br class=""><br class=""><br class="">*Future directions:*<br class="">"conform(ProtocolName)" / "override(ProtocolName)" can be used to disambiguate.<br class=""><br class="">// reducing boilerplate<br class="">extension Foo: conform Bar {<br class="">&nbsp; // These declarations can only implement Bar and don't need the<br class="">"conform" keyword<br class="">}<br class=""><br class="">*Final question:*<br class="">Should we also require a marker for implemented protocol members in the<br class="">interface?:<br class=""><br class="">protocol Foo {<br class="">&nbsp; defaulted func foo()<br class="">}<br class="">extension Foo {<br class="">&nbsp; implement func foo()<br class="">}<br class=""><br class=""><br class="">Best regards<br class="">Maximilian<br class=""><br class="">Am 22.09.2016 um 16:44 schrieb Vladimir.S via swift-evolution<br class="">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;&gt;:<br class=""><br class=""><blockquote type="cite" class="">On 22.09.2016 11:10, Jean-Denis Muys via swift-evolution wrote:<br class=""><blockquote type="cite" class="">I watched this thread with a lot of attention, starting neutral. You<br class="">must say that Karl won me over. His proposal would make Swift more<br class="">expressive, and less error prone in cases of protocol conformance with<br class="">name collisions. I am at this point +1<br class=""></blockquote><br class="">Actually I also support Karl's suggestion in general. It is trying to<br class="">solve IMO important problems and make Swift's protocol programming safer<br class="">and less fragile. Also it adds new interested features for working with<br class="">protocols.<br class=""><br class="">But in reality, I don't feel like his suggestion could be accepted by<br class="">core team and community and even if it could be supported, it seems for<br class="">me that *implementation* of his proposal requires a huge amount of time<br class="">and big changes in how Swift is working currently. (Probably some one who<br class="">knows Swift internals could comment regarding this)<br class="">So, theoretically we'd have these improvements not in near future and I<br class="">think the problem discussed is very important to be addressed in Swift as<br class="">soon as possible.<br class="">I base my opinion also on previous discussions regarding similar subjects.<br class=""><br class="">My suggestion regarding a marker for protocol implementation method/prop<br class="">in type - solves most of the addressed problems with protocol conformance<br class="">and with fragile of such conformance, and adds one new keyword (or even<br class="">zero - right now I think the `override` is better choice for such<br class="">"marker"). I believe this proposal could be implemented with much less<br class="">amount of work and with less changes to current internals of Swift and to<br class="">current code base, and so we can have such a big improvement in Swift<br class="">soon. So my intention was to suggest solution that can dramatically<br class="">improve Swift's protocol programming with "small" amount of changes for<br class="">compiler(internals) and for existed sources.<br class=""><br class="">But it seems like the direction chosen by the core team and supported by<br class="">many in community - is just a warning if extension conforming type to<br class="">protocol contains unrelated to that protocol methods/props. I see that<br class="">this solution can improve protocol programming in some areas, but does<br class="">not address some IMO important issues we discussed in the thread :<br class=""><br class="">* Currently extension can not have stored properties. So, if we want to<br class="">implement protocol's props as stored properties - we can't move them to<br class="">extension. So to implement this soulution - we need stored properties in<br class="">extensions. It is not clear if and when they are expected.<br class=""><br class="">* This solution will not require the safety(regarding protocol<br class="">conformance) from a developer, it will only inform and only if protocol<br class="">conformance defined in extension. So, when you use 3rd party source code<br class="">- your project will not be protected for the discussed problems.<br class=""><br class="">* To write safe code I can't group methods/props as I want, I have to<br class="">declare a number of extensions per-protocol (in case my type conforms to<br class="">a number of protocols)<br class=""><br class="">* This solution does not solve problem of near-miss signature of method<br class="">definition in protocol extension like here:<br class="">protocol A { func foo() }<br class="">protocol B : A {}<br class="">extension A { func foo() }<br class="">extension B { func voo() } // typo. how to "mark" this should be impl?<br class="">"my" suggestion:<br class="">extension A { override func foo() }<br class="">extension B { override func foo() }<br class=""><br class="">* Not clear how to write safe code with that approach if we implement<br class="">protocol requirement in derived class, but conformance was declared in<br class="">base (but not implemented) :<br class="">protocol P { func foo() }<br class="">extension P { func foo() }<br class="">class A : P {}<br class="">class B { func foo() } // we can't move this to extension, B already<br class="">conforms to P<br class="">, and in opposite to "my" `override` requirement for implementation, if<br class="">`A` will add its own foo() implementation - we'll have to change B's<br class="">definition(need to add `override` for B.foo )<br class="">"my" suggestion:<br class="">class B { override func foo() }<br class=""><br class=""><br class=""><blockquote type="cite" class=""><br class="">Jean-Denis<br class=""><br class="">Sent from my iPhone<br class=""><br class=""><blockquote type="cite" class="">On 22 Sep 2016, at 07:15, Karl via swift-evolution<br class="">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;&gt; wrote:<br class=""><br class="">I would like to make it a requirement if not inside a protocol<br class="">extension which declares a conformance, and actually build the<br class="">protocol name in to the member in an ABI-breaking way. We could make<br class="">it additive by generating forwarding thunks from the old symbols to<br class="">the new ones, but it would be better if we could just solve the<br class="">overlapping-members problem before then.<br class=""><br class="">That would mean you never get collisions between protocol members.<br class="">There’s loads of amazing stuff we can do with that ability, and ways<br class="">we can extend it to reduce a lot of boilerplate that occurs when you<br class="">want to have multiple representations of the same data (String is just<br class="">an example).<br class=""><br class="">I don’t really care about the syntax we need to make it liveable. We<br class="">could automatically insert the protocol names for unambiguous members<br class="">at call-site, or something else.<br class=""><br class="">This thread was originally about making the *syntax* a requirement; I<br class="">agree with that, and I would actually take it one (or several) steps<br class="">further, solving other problems along the way.<br class=""><br class=""><blockquote type="cite" class="">On 22 Sep 2016, at 06:46, Russ Bishop &lt;<a href="mailto:xenadu@gmail.com" class="">xenadu@gmail.com</a><br class="">&lt;<a href="mailto:xenadu@gmail.com" class="">mailto:xenadu@gmail.com</a>&gt;&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Sep 20, 2016, at 4:34 PM, Dave Abrahams via swift-evolution<br class="">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">on Tue Sep 20 2016, Karl &lt;<a href="http://razielim-at-gmail.com" class="">razielim-AT-gmail.com</a><br class="">&lt;<a href="http://razielim-at-gmail.com" class="">http://razielim-AT-gmail.com</a>&gt;&gt; wrote:<br class=""><br class="">I think the best way is to prefix the member name with the<br class="">protocol, e.g:<br class=""><br class="">protocol MyProto { var aVariable : Int func aFunction() } class<br class="">MyClass : MyProto { var MyProto.aVariable : Int func<br class="">MyProto.aFunction() { … } }<br class=""></blockquote>...<br class=""><blockquote type="cite" class="">CC-ing Dave A, to understand better if this fits with the vision<br class="">of protocols<br class=""></blockquote><br class="">I generally agree with Doug. &nbsp;The canonical way to indicate “this<br class="">method/property/type implements a requirement of protocol P”<br class="">should be to define the entity in an extension that also adds<br class="">conformance to P. If that's inadequate indication in some way we<br class="">should find a way to enhance it. &nbsp;I wouldn't mind the notation<br class="">above, but only as a fallback, not a reuquirement.<br class=""><br class="">-- -Dave _______________________________________________<br class=""></blockquote><br class="">Indeed this is exactly how C# handles Interfaces (protocols). The<br class="">default is the exact same way Swift works - by matching names. If<br class="">there is a collision you specify Protocol.memberName. Its simple and<br class="">in the years I was writing C# code it was flexible enough to cover<br class="">most reasonable scenarios, without adding a bunch of boilerplate.<br class=""><br class="">Russ<br class=""><br class=""></blockquote><br class="">_______________________________________________ swift-evolution<br class="">mailing list <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;<br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote>_______________________________________________ swift-evolution mailing<br class="">list <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;<br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><br class=""></blockquote>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;<br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote></blockquote>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class=""><br class=""></blockquote></blockquote><br class=""></body></html>