Comment

Comment by phaylon

I'm not a Python developer, but in general metaclasses are classes represented as objects. You can also have objects for methods, attributes, and whatever else your object system provides. These objects of course also have classes that you can subclass and extend, apply traits to, and so on.

This is very useful for introspection and dynamically building class structures. Which extends to it being also a common API for extensions to your classes (I'm playing with a Perl/Glib project using the Moose MOP framework to allow Perl classes to have Glib signals, for example). Speaking for Perl/Moose, it's regularly used to modify or extend the behavior/capabilities of attributes (by applying traits to them).

Even just the introspective aspect means your program can easily know about the structure of your classes, for serializations, debugging, proxying, auto-generating documentation, auto-generating command line arguments, and so on.

This is just a rough outline, and in no way complete. I'd guess here's a good language-agnostic starting point: http://en.wikipedia.org/wiki/Metaobject

parent phaylon 14 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton