[swift-evolution] [Pitch] Rename Mirror

Anton Zhilin antonyzhilin at gmail.com
Wed Aug 10 17:32:04 CDT 2016

2016-08-11 0:40 GMT+03:00 Slava Pestov <spestov at apple.com>:
> I think pointing a Mirror at a metatype value could be a good a mechanism
> for getting information about the type's stored properties and other
> members.
> FWIW Mirrors are inspired by a feature of the same name in the Self
> language, which made reflection somewhat more principled than the
> disorganized APIs you see in Java and C#. Perhaps the latter are not a good
> model to follow here :-)

Swift and Self lie in different families of languages.
In Self (and Smalltalk, and ObjC), types don't really matter: one can
modify methods, which some object has, independently of all other objects.
Because of this dynamism, reflection of types has little value in these

On the other hand, in Swift (and C++, and Java) types do matter. It is
useful to get, for example, a Method, and be sure that you can call it on
all instances of matching type.
I think that Swift should favor types and not instances, as it
unfortunately does today.

This is how I imagine reflection API. We have a type ID and can request
different information about it. For example:  func getMethod(name: String)
-> Method?
Most importantly, we should be able to get IDs of other related types, and
related type IDs of theirs, and so on, without collecting excessive data.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160811/b380610b/attachment.html>

More information about the swift-evolution mailing list