Open mickranger opened 7 years ago
Sorry, I somehow overlooked this. - Your suggestion makes sense. I plan to overhaul the serialisation aspect at some point (see #43), so this may features in this work. If you are doing serialisation perhaps you have some comments to make on that issue.
Hi billy,
i really like the library and i'm familiarizing with it. I only struggled when I wanted to make a registered type a property of another registered type, which i consider a quite common case. It took me a while to understand why my code failed.
Currently,
ponder::Class::declare()
allows to specify an alternative name for the type. However, internally, this is not an alias name but replaces the statically deduced type id (see also #61). The drawback of this decision is thatponder::classByType<>()
does not work if the specified name is not identical to the original fully qualified type. For instance, the following snippet would raiseClassNotFound
at runtime:This is not a big deal as long as
ponder::class ByType<>()
can be avoided becauseponder::classByName()
can do the trick. However, it is not always possible to circumvent lookup by type. When theClassBuilder
adds a property, it needs to figure out its type. The current implementation deduces the type statically, which results in a very comfortable and safe interface. However, type look-up will fail if the property refers to a registered type which has a name different from the fully qualified type. Thus, callingdeclare()
in the following code would raiseClassNotFound
:That limits the usability of the alternative name quite a bit. Being able to define aliases for type names is invaluabe for serialization, so I suggest separating
id
andname
inClass
, makingname
default to the type, and enable theClassManager
to lookup explicitly by name.What do you think?