[swift-evolution] [Proposal] Disallow redundant `Any<...>` constructs

Matthew Johnson matthew at anandabits.com
Fri May 20 19:55:58 CDT 2016

> On May 20, 2016, at 6:56 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>> Austin, what is your thought on switching to `any` rather than `Any` since it does not behave like a user-defined generic type?  The convention is for types to be uppercase and keywords to be lowercase.  This falls more into the category of a keyword and has its own behavior distinct from the behavior of all generic types.  Making it stand out syntactically will help to make that clear.
> You didn't ask me, but I'll weigh in: I'm not a fan.

Sorry, I asked Austin because he is heading up the proposal.  Didn’t meant to leave anyone out.  Thanks for providing feedback!

> * I think `Any` (without parameters) should be uppercase, and I don't think we should have both `Any` and `any<>` or `any`. Death to the typealias!

Why do you think this?  `any<>` (or `Any<>`) is replacing `protocol<>`.  `protocol` is a keyword, so following the convention you shared it should be all lowercase.  Aside from that, it behaves differently than a user-defined type (which would be uppercase).

> * If type-erasing structs like `AnySequence` are eventually subsumed by this syntax, I would prefer they be called `Any<Sequence>` instead of `any<Sequence>`.

Are you arguing this because they are types?  They are currently structs.  If they were subsumed by this proposal they most definitely would not be structs.  If it’s just syntax you’re concerned with, we could add a typealias:

typealias AnySequence<T> = any<Sequence where .Iterator.Element == T>

I haven’t evaluated AnySequence relative to the existential this typealias would produce.  If the visible interface is compatible there would be a strong argument for introducing this typealias.  The argument for lowercase wouldn’t apply to the typealias.

> * In the `willSet` vs. `willset` thread, I proposed a rule that keywords which fit into a particular syntactic slot should be capitalized like normal members of that slot. For instance, if `dynamicType` is a pseudo-property, it should be capitalized like a property. Since `Any<>` fits in the syntactic slot of a type, it should be capitalized like a type.

Any has some overlap with types, but it cannot be used everywhere a type can.  This is precisely why it should be lowercase.  I don’t believe it falls under that exemption in your proposal.  I believe it’s a good exemption when the keyword is indistinguishable to users from a normal member.  I don’t believe it’s a good exemption when the behavior is “special” in some way.


> -- 
> Brent Royal-Gordon
> Architechies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160520/54301588/attachment.html>

More information about the swift-evolution mailing list