[swift-evolution] Keyword for protocol conformance

Robert Widmann devteam.codafi at gmail.com
Tue Aug 23 22:34:22 CDT 2016



~Robert Widmann

2016/08/23 15:29、Charles Srstka <cocoadev at charlessoft.com> のメッセージ:

>> On Aug 23, 2016, at 2:33 PM, Robert Widmann via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> 2016/08/22 14:30、David Cordero via swift-evolution <swift-evolution at swift.org> のメッセージ:
>> 
>>> 
>>> The problem:
>>> At the moment, looking at the code of a class or a struct implementing a protocol, it is hard to know what methods are actually implementing the protocol and what other methods are just part of the code of the class or struct.
>> 
>> That seems like a feature, not a bug.  Why should I as an author care whether a method contributes to a protocol conformance or not if the compiler can tell me that kind of information itself?
> 
> Being able to reason about your code, what it does, and what it’s for is undesirable?

That's not an answer to the question I asked.  Why is this significant enough to warrant an entire keyword?  The clutter of a whole keyword that does nothing but wait for a developer to make a source-compatible binary-breaking change to an interface does not seem worth it.  Maybe you can convince me otherwise. 

> 
>>> ```
>>> protocol MyProtocol {
>>>     func myMethod() -> String
>>> }
>>> 
>>> class MyClass: MyProtocol {
>>> 
>>>     conform func myMethod() -> String {
>>>         return "Yuhuuu,I am conforming \\o//"
>>>     }
>>> 
>>>     func whatever() {
>>>         print("I am a boring method and I don't conform anything")
>>>     }
>>> }
>>> ```
>>> 
>>> It would be something similar to the current keyword `override` but for protocols. 
>>> 
>>> Apart from improving code readability, It would allow the detection, in compilation time, of errors due to code evolution. For example redundant methods that no longer conform anything once the requirement is removed from the protocol for whatever reason.
>> 
>> If you make a breaking change to a protocol like this, you should have gone through a deprecation cycle to indicate to your clients the appropriate changes you're going to make to the protocol.  This aspect of the change seems to if not encourage, highlight, bad behavior.
> 
> What if it’s your own code and all the callers are internal? What if you’re still developing the protocol and haven’t released the API interface yet?

Then your concerns are local enough that you know where all implementations of the protocol lie and whether they require deletion or not.  The point about deprecation cycles still stands in all the cases you mention.  Just because the interface is private doesn't mean you can't take responsibility for keeping it as clean as you can.

> 
> Charles
> 

tl;dr It seems like all of this can be subsumed by us warning about dead code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160823/1df0b3f9/attachment.html>


More information about the swift-evolution mailing list