[Swift] Protocol adoption syntax is horrible and potentially confusing

Originator:amolloy
Number:rdar://17302943 Date Originated:6/13/14
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:
 
Currently, to signal that a Swift class adopts one or more protocols, the protocols are listed in a comma separated list following a colon after the class name, like so:

class AClass : AProtocol, AnotherProtocol { ... }

If the class has a superclass, the superclass is placed in the same list, and must appear first:

class AClass : AnotherClass, AProtocol, AnotherProtocol { ... }

This leads to significantly reduced readability and maintainability of this code. Because there is no syntactical distinction between a superclass and a protocol, somebody familiarizing themselves with the code will have to spend time discovering whether the class inherits from another class, or simply adopts one or more protocols. Arguably, they will need to do so at some point anyway, but compare to Objective-C's syntax:

@interface AClass : AnotherClass <AProtocol, AnotherProtocol> ... @end

There is an extremely clear visual distinction between the superclass and the adopted protocols. Yes, our supposed maintenance programmer will almost certainly eventually need to learn what these things do, but at least with this syntax they can know at a glance what is a superclass and what is an adopted protocol.

Objective-C's syntax is clean and highly readable, and I think the best option would be to duplicate it (with a Swift-style):

class AClass : AnotherClass <AProtocol, AnotherProtocol> { ... }

That said, just about any syntax where there is a clear distinction between superclass and adopted protocol would be a significant improvement over the current syntax. Even Java's  verbose syntax is more easily understood:

class AClass extends AnotherClass implements AProtocol { ... }

It is a rare day indeed where I suggest anything from Java is good, but this is unquestionably better than Swift's current syntax.

Steps to Reproduce
N/A

Expected Results
N/A

Actual Results
N/A

Configuration
Any

Xcode Version
Xcode 6 Beta 1

Additional Notes

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!