[swift-evolution] Proposal: Change of syntax for class protocols

Felix Gabel felix.gabel at me.com
Mon Dec 7 16:29:22 CST 2015


Great to hear about being able to apply this to type parameters and associated types in the future. But I still propose to rethink the syntax decision. 
 
class protocol FooType {}
typealias class Bar: FooType
func foo<class T>()

This is more consistent with for example the declaration of a class or property

Construct name: Type

> On 07 Dec 2015, at 23:04, Douglas Gregor via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>>> On Dec 7, 2015, at 8:58 AM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> 
>>> On Dec 7, 2015, at 8:00 AM, Matthew Cheok via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> Currently, we declare class protocols with the following syntax:
>>> 
>>> protocol TestProtocol: class, OtherProtocol {}
>>> 
>>> This is odd for a few reasons:
>>> 1) The keyword class exists in the middle of the declaration
>>> 2) The keyword class follows the colon and looks a lot like inheritance
>>> 3) The keyword class occupies a somewhat arbitrary first position after the colon (otherwise we have an error)
>>> 
>>> We also have another use of the class keyword as a modifier when declaring class methods:
>>> 
>>> class func doSomething() {}
>>> 
>>> I’m suggesting a change of syntax that rectifies the above issues:
>>> 
>>> class protocol TestProtocol: OtherProtocol {}
>>> 
>>> Would love to hear other thoughts on this.
>> 
>> The constraint syntax is used because, in the fullness of time, it should also be applicable to type parameters and associated types:
>> 
>> protocol Foo { typealias T: class }
>> 
>> func foo<T: class>(x: T)
> 
> 
> Right. This is exactly the reason why we have the syntax
> 
> 	protocol X : class { … }
> 
> and why I’m against changing the current syntax.
> 
> 	- Doug
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151207/421b8f95/attachment.html>


More information about the swift-evolution mailing list