[swift-evolution] [swift-evolution-announce] [Review] SE-0089: Replace protocol<P1, P2> syntax with Any<P1, P2>

Thorsten Seitz tseitz42 at icloud.com
Wed May 25 05:58:48 CDT 2016




Am 25. Mai 2016 um 09:34 schrieb Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org>:


 * What is your evaluation of the proposal?

I am in favor. This is a necessary step towards many future features: class-plus-protocol types, the replacement/reimplementation of AnyObject with Any<class>, existentials with associated types, etc.

One reason to prefer `Any` over `any` which is not listed in the proposal is confusion with the unparameterized `Any` type. Having an uppercase `Any` and a lowercase `any<…>` is going to lead to a lot of confusion; people aren't going to remember whether they need the capitalized form or the lowercase one for any particular use. I don't think we can have `any<...>` unless we're also willing to have an unparameterized `any`, and I think `any` is 100% wrong, because it is absolutely a type but is lowercase.

Since we are trying to cram as many breaking changes as possible into Swift 3, I also think we should consider now, or soon, whether or not we want to draw a strong syntactic line between protocols-as-existentials and protocols-as-constraints by requiring the use of `Any<…>` on all existentials and forbidding its use in constraints. That would mean, for instance, that code like this:

     let printable: CustomStringConvertible = foo

Would now be written:

 let printable: Any<CustomStringConvertible> = foo

And also that code like:

     func foo<X: Any<Y, Z>>(x: X)

Would probably have to be written something like:

 func foo<X: Y>(x: X) where X: Z


Although I am strictly against having to write non-existential protocols as existentials (as I have written in another post), I also think that it would be desirable to use existentials only for declaring types of variables or parameters etc. but not for defining constraints, i.e.


let printable: CustomStringConvertible = foo     // fine, CustomStringConvertible is not an existential

let coll: any<Collection>    // allowed usage of existential

func foo<X>(x: X) where X: Y, Z    // existential any<Y, Z> not allowed here



-Thorsten









However, I believe this would have a significant advantage: it would clarify the distinction between an existential and a constraint. It would more clearly mark where you are taking on the abstraction overhead of an existential. It would also improve the non-existential type situation: in the short term, it would make it clearer where uses of associated type protocols like `Comparable` would not be permitted; in the long term, once we have type-erased existentials for those protocols, it would make it clearer when type erasure was in effect.


     * Is the problem being addressed significant enough to warrant a change to Swift?

Yes. `protocol<>` is an ugly and unloved corner of the language; very few people know about it, remember it, or use it. The renaming improves this situation.


   * Does this proposal fit well with the feel and direction of Swift?

Given the way it enables many future features, yes.


   * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

The only language I've used with similar features is Objective-C. There, too, the `<>` is overloaded, now that lightweight generics are part of the language.


       * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

I'd like to think I have a fairly deep understanding of this feature, having participated heavily in the discussions about it.

--
Brent Royal-Gordon
Architechies

_______________________________________________
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/20160525/dd1fd3e4/attachment.html>


More information about the swift-evolution mailing list