[swift-evolution] Mark protocol methods with their protocol
    Martin Waitz 
    tali at admingilde.org
       
    Fri Sep 23 07:58:08 CDT 2016
    
    
  
Hello :)
Am 2016-09-23 08:50, schrieb Rien:
> 
> > -- module A --
> > class A {
> >   func foo() {}
> > }
> >
> > -- module B --
> > protocol Foo {
> >   func foo()
> > }
> > extension A: Foo {}
> 
> let c = A()
> 
> I’d say that you have two functions here:
> A.foo() and A.Foo.foo()
No. Now (i.e. within module B) A conforms to Foo, using the already 
existing function.
> Note that A.foo() was never intended to be used as an implementation
> for protocol Foo, thus why should you be able to see it as such? That
> imo is a bug in the language. Its not flexibility, it’s dangerous.
I disagree, this is the great thing about Swift.
It's exactly in the middle between Go's "everything is considered to 
implement a protocol if it happens to provide the right methods" and 
C++/younameit's "you have to know everything in advance and people are 
screwed if the library does not use the right protocols" style.
You can add protocol conformance to classes you don't control, but you 
have to explicitly declare this conformance.
I think this is exactly the right approach.
-- 
Martin
    
    
More information about the swift-evolution
mailing list