Introspection in AS3 August 4, 2007
One of my design philosophies is leveraging technology to help create better technology. In design, this means using introspection to help validate the design elements, and autocreate classes. In coding this involves using introspection to help generate unit tests, and do class validation when you're doing things like function pointers, linked lists, static initialization.
One of the recent projects/framework named Cogs, a state machine (to be discussed more in future posts), uses function pointers extensively. So I use introspection to get the names dynamically of the states and validate the hierarchy, so coders can focus on developing the application instead of housekeeping. In languages in Java, introspection is quite powerful. In flash I was excited to see the potential of describeType(), which outputs an XML describing the class/instance.
Unfortunately in practice it's been limiting, introspection sees have to be marked as 'public' as anything else isn't visible. In particular protected and custom namespaces can't be introspected, even within the same namespace. Meaning a class can't introspect itself, even though it has access to the private/protected members of itself via normal code, or it's children, or utilities in the same package. This means custom namespaces and protected in regards to don't work like they do with variables, or functions.
This sucks. for-in is now limited to things on the prototype chain or plain objects, which are probably empty if your using standard classes. With describeTypes limitations seems crippled, limiting it's usefulness except for all but the simplest data types, or specifying everything by hand which is brittle.

Add a Comment: