On 21.09.2016 2:34, Dave Abrahams via swift-evolution wrote:


on Tue Sep 20 2016, Karl <razielim-AT-gmail.com> wrote:

I think the best way is to prefix the member name with the protocol, e.g:

protocol MyProto {
    var aVariable : Int
    func aFunction()
}
class MyClass : MyProto {
    var MyProto.aVariable : Int
    func MyProto.aFunction() { … }
}
...
CC-ing Dave A, to understand better if this fits with the vision of protocols

I generally agree with Doug.  The canonical way to indicate “this
method/property/type implements a requirement of protocol P” should be
to define the entity in an extension that also adds conformance to P.

Could you clarify, how do you see a solution in case extension can't have stored properties? So, if protocol has such requirement(i.e. we want to implement the protocol requirement as stored property) we can't move it to extension.
Do you expect we'll have stored props in extension in near future?

Also, what about protocol extensions? What do you suggest to mark default implementation method here to express intention and to separate default implementation (that depends on protocol definition and so, IMO compiler should help us if protocol definition changed) from just helper methods in protocol extension? Like here:

protocol A {
    func foov()
}

protocol B : A {
}

extension A {
    func foov() {}
}

extension B {
    // I was expecting this is a default implementation of foov() for B
    // but in reality this is a helper method
    // who knows when this error will be detected
    func foow() {}
}

If that's inadequate indication in some way we should find a way to
enhance it.  I wouldn't mind the notation above, but only as a fallback,
not a reuquirement.


Could you share your opinion (and probably some common opinion of the core team) regarding `implement`(or `override`) keyword requirement for methods/props in type declared exactly to implement protocol's requirements?

Don't you feel that if Swift will not *require* this, we'll have fragile code base as, even if *I* can use linter for this, 3rd party source code that will be in my project probably will not use the "safe" method of protocol conformance?
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to