[swift-evolution] [Pitch] Rename `x.dynamicType` to `x.Self`

Joe Groff jgroff at apple.com
Fri Apr 15 11:33:26 CDT 2016


> On Apr 15, 2016, at 3:19 AM, Taras Zakharko <taras.zakharko at uzh.ch> wrote:
> 
> True, that makes sense. I was simply trying to explore different possibilities of how these things could be represented in the syntax. What about #type(d) for static (declaration) type and type(v) for dynamic (value/instance) type? Or would that be potentially confusing as well? 
> 
> The reason why I dislike .dynamicType etc. declarations is because they introduce another ‘magic’ properties to instances. I think that this functionality is very important and that it should be represented by the standard library instead. If Swift had a universal base type, one could say that the magic properties are just part of that base type (and by extension, part of the standard library), however, right now, they are injected by the compiler. I’d rather have a standard function like 
> 
> type: (Any)->AnyType 
> 
> for this purpose. Hell, I would even say that dynamicType(self) is an improvement over self.dynamicType :)

The way I see it, my proposed change reduces the total amount of magic. Associated types *are* members of their parent type, and `Self` is a special case of an associated type.

-Joe


More information about the swift-evolution mailing list