[swift-evolution] Changing postfix "self" to something clearer like "type"

Dennis Lysenko dennis.s.lysenko at gmail.com
Tue Dec 15 10:34:56 CST 2015


+1. Side effects can be eliminated through code migration if a suitable
property name is chosen. Perhaps `staticType` to continue in the vein of
`dynamicType`?

Main detractor is that creating more keywords isn't necessarily a good
thing.

On Tue, Dec 15, 2015 at 11:19 AM Brandon Knope via swift-evolution <
swift-evolution at swift.org> wrote:

> One area of swift that is really not clear to me is when you want to use
> the type of a class, struct, enum, etc as a value.
>
> Metatyping is explained here:
> https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-XID_1022
>
> Example:
>
>    1. let metatype: SomeClass.Type = SomeClass.self
>
>
> Is there a reason why this isn't SomeClass.type? Everywhere in the
> document this is explained as returning the type yet it's using a postfix
> self to access the type.
>
> I propose changing the postfix self to something more obvious like "type"
>
> Going back to the example:
>
>    1. let metatype: SomeClass.Type = SomeClass.type
>
>
> Several reasons why I think this is better:
> 1. Postfix self is not obvious as an option as you never see a postfix
> self anywhere else
> 2. "self" does not clearly explain that the type is being returned
> 3. ObjC programmers are familiar with accessing the class type by sending
> the "class" method to the class type. In this case it needs to work on
> structs and enums, so a "type" method would make more sense.
> 4. Instances have a dynamicType method. For consistency, classes, structs,
> etc., should have a type method
>
> Any other suggestions would be welcome.
>
> Brandon
>
> Sent from my iPad
> _______________________________________________
> 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/20151215/381df94b/attachment.html>


More information about the swift-evolution mailing list