[swift-evolution] [Pitch] separate syntax of class inheritance and protocol conformance

Vladimir.S svabox at gmail.com
Fri Jul 22 11:13:07 CDT 2016


 > Perhaps a change to Xcode so it could colour differently classes and
 > protocols could be more benefic with no impact to the language. That
 > would solve the problem.

IMO no enhancement in *IDE* could solve the problem of *language*.
Swift code will be written/viewed not only in XCode and even not only in IDE.

On 22.07.2016 18:56, Leonardo Pessoa wrote:
> I don't see this as an issue and I'm sure not comfortable in being
> more verbose here or complicating the language unnecessarily. This is
> not a change that will bring either benefit or consistency as there
> are no other cases to compare the use of colon but these and variable
> declarations (which also use only one).
>
> Perhaps a change to Xcode so it could colour differently classes and
> protocols could be more benefic with no impact to the language. That
> would solve the problem.
>
> L
>
> On 22 July 2016 at 12:13, Karl via swift-evolution
> <swift-evolution at swift.org> wrote:
>> What about if we defined subclasses with the “subclass” keyword instead of “class”? So you knew the first parameter was always going to be a base class?
>>
>> That way we keep the single “:” everywhere else - where clauses, generic constraints lists, etc.
>>
>>> On 22 Jul 2016, at 15:14, Vladimir.S via swift-evolution <swift-evolution at swift.org> wrote:
>>>
>>> I remember that this was discussed, but can't find any decision regarding this.. So, as a last chance, don't we want in Swift 3.0, as big source breaking change, separate class inheritance and protocol conformance in syntax?
>>>
>>> Sorry if there was a decision about this suggestions. Please let know in this case.
>>>
>>> I.e. when I see the following I can't understand if the class inherits from base class and conforms to protocols or just conforms to two protocols:
>>>
>>> class MyClass : First, Second, Third {
>>> }
>>>
>>> We don't have a rule to name protocols with 'Protocol'/other suffix/prefix, or classes with 'T'/'C' prefix or something like this, so I believe to improve the clarity of code we should separate in syntax inheritance and conformance.
>>>
>>> As I understand we should discuss changes in these areas:
>>>
>>> 1. class inheritance :
>>> class Child: BaseClass
>>>
>>> 2. class conformance :
>>> class Child: SomeProtocol1, SomeProtocol2
>>>
>>> 3. class inheritance + conformance :
>>> class Child: BaseClass, SomeProtocol1, SomeProtocol2
>>>
>>> 4. protocol conformance for structs:
>>> struct Struct: SomeProtocol1, SomeProtocol2
>>>
>>> 5. protocol inheritance:
>>> protocol Child: BaseProtocol1, BaseProtocol2
>>>
>>>
>>> My suggestions:
>>>
>>> I) separate inheritance with double colon :
>>>
>>> 1. class inheritance :
>>> class Child:: BaseClass
>>>
>>> 2. class conformance :
>>> class Child: SomeProtocol1, SomeProtocol2
>>>
>>> 3. class inheritance + conformance :
>>> class Child:: BaseClass : SomeProtocol1, SomeProtocol2
>>>
>>> 4. protocol conformance for structs:
>>> struct Struct: SomeProtocol1, SomeProtocol2
>>>
>>> 5. protocol inheritance:
>>> protocol Child:: BaseProtocol1, BaseProtocol2
>>>
>>>
>>> II) in class definition use parenthesis to separate inheritance and conformance :
>>>
>>> 1. class inheritance :
>>> class Child: BaseClass
>>>
>>> 2. class conformance :
>>> class Child: (SomeProtocol1, SomeProtocol2)
>>>
>>> 3. class inheritance + conformance :
>>> class Child: BaseClass (SomeProtocol1, SomeProtocol2)
>>>
>>> 4. protocol conformance for structs:
>>> struct Struct: SomeProtocol1, SomeProtocol2
>>> or
>>> struct Struct: (SomeProtocol1, SomeProtocol2)
>>> should be discussed
>>>
>>> 5. protocol inheritance:
>>> protocol Child: BaseProtocol1, BaseProtocol2
>>>
>>>
>>> III) special word like 'conforms'
>>>
>>> 1. class inheritance :
>>> class Child: BaseClass
>>>
>>> 2. class conformance :
>>> class Child: conforms SomeProtocol1, SomeProtocol2
>>> or
>>> class Child conforms SomeProtocol1, SomeProtocol2
>>>
>>> 3. class inheritance + conformance :
>>> class Child: BaseClass conforms SomeProtocol1, SomeProtocol2
>>>
>>> 4. protocol conformance for structs:
>>> struct Struct: conforms SomeProtocol1, SomeProtocol2
>>> or
>>> struct Struct conforms SomeProtocol1, SomeProtocol2
>>>
>>> 5. protocol inheritance:
>>> protocol Child: BaseProtocol1, BaseProtocol2
>>>
>>>
>>> Thoughts?
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>


More information about the swift-evolution mailing list