MetaData and MetaProgramming afford a lot of power to programmers. One problem, however, is that most languages don't provide an easy way for developers to attach custom meta-data to program elements like member data, methods, and classes.
Custom meta data can be very useful when ReflectiveProgramming is done. Here are some examples from the ScarletLanguage (Scarlet allows you to tag program elements with arbitrary identifiers called attributes):
- Many implementations that use reflection to process object data look for an internal-state attribute. This is used to mark data that doesn't affect the logical state of the object (stuff like internal caches). Most of these implementations also check for an attribute that can be used to override the internal-state attribute. For example, Clone will always copy data that has the clone attribute.
- Methods in interfaces can be labeled with the optional attribute. These methods do not need to be implemented so clients must test for their existence before calling them.
- The unit test code grovels though every object in the system looking for methods with the unit-test attribute. If it finds one it sticks it in a list and runs it when the user wants to run the tests.
The
CsharpLanguage also makes rather heavy use of custom meta-data. In C# however, attributes are full fledged objects so they are a bit more powerful that those in Scarlet.
http://www.ondotnet.com/pub/a/dotnet/2003/07/28/understadingattributes.html has a good introduction to attributes in C#.
It's coming in Java as well. http://www.langrsoft.com/articles/annotations.html
--JesseJones
CategoryReflection