[swift-evolution] [Pitch] separate syntax of class inheritance and protocol conformance
Ross O'Brien
narrativium+swift at gmail.com
Fri Jul 22 08:41:07 CDT 2016
I think we're making incremental progress here. The idea of declaring a
property which inherited from a given class and conformed to given
protocols has definitely been discussed, but hasn't been reviewed (I don't
know offhand whether it's scheduled or even formally written up). The idea
of writing this for the declaration of the type itself might be new, I'm
not sure.
I think SE-0095 - declaring multiple protocol conformances with '&' - was
part of that progression, which might address some of your pitch, e.g. this
example could be a bit clearer:
class Child: BaseClass, SomeProtocol1, SomeProtocol2
would now be
class Child: BaseClass, SomeProtocol1 & SomeProtocol2
Is some of this waiting on a fully thought out syntax for types including
existentials?
On Fri, Jul 22, 2016 at 2:14 PM, 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160722/c37339d2/attachment-0001.html>
More information about the swift-evolution
mailing list