I’ve wondered this as well. Using “self.dynamicType” is noisy and somewhat 
esoteric, and using “MyStruct.foo” is bad the moment you want to rename 
“MyStruct”.

l8r
Sean


> On Apr 4, 2016, at 1:00 PM, Erica Sadun via swift-evolution 
> <[email protected]> wrote:
> 
> Are there reasons that prevent using `Self` as a synonym for an instance's 
> type name?
> 
> Consider:
> 
> struct MyStruct {
>     static func foo() { print("foo") }
>     func bar() {
>         MyStruct.foo() // works
>         self.dynamicType.foo() // works
>         Self.foo() // error
>     }
> }
> 
> Obviously, you can always name a type directly or use `self.dynamicType` but
> neither solution does any favors for readability. Both approaches obscure 
> intent, 
> especially as type names grow large: `MyExtremelyLargeTypeName.staticMember`,
> for example. Plus, as Kevin B pointed out to me,  
> `self.dynamicType.classMember`  
> and `TypeName.classMember` may not be synonyms in class types with non-final 
> members.
> 
> I'd like to see `Self.staticMember` introduced as a synonym for 
> `TypeName.staticMember`.
> 
> Thoughts?
> 
> -- E
> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to