As I'm sure all of you who read this blog (all three of you) know, I'm a bit of a pedantic bore... okay, I'm a big pedantic bore. I just love teaching, particularly obscure technical things that are so dry and abstract that no one in their right mind could possibly be interested in them.
I love to systematise and organise things for people, then present them in the hopes that others will see the magic of the emerging pattern. It gives me a charge to try to model how the listener will interpret the ideas and to try to tailor the lecture to improve their understanding.
One of the most rewarding comments I've ever had on a lecture was from someone extremely versed in metaclasses, who, after listening to my metaclasses presentation at the last PyCon came up to me and said (paraphrased) "Wow, so it turns out metaclasses are even scarier than I thought". Which was one of the core ideas I was trying to get across; this idea that metaclasses should be scary because they introduce new magic; that using one should always be a considered movement.
Metaclasses are the philosophy of classes. It's seldom a good idea to use philosophy to solve mundane problems. To use a metaclass is to make a statement about the very nature of what it means to be an object, and when you alter the fundamentals of what it means to be an object, you force everyone who lives in the world you create to re-learn their model of the world.
That position lead, in part, to the discussion that prompted me to offer this little lecture at PyGTA. Tim came over to work on one of his projects, and as part of this he wanted to create a constrained string datatype. However, I'd disconnected the constraints system in BasicProperty until I had a chance to rework it "properly", so he was intending to create a string sub-class that would enforce the constraints to create an "email" class.
As we worked; with my basically tossing out magic item after magic item (things Tim had either never heard of, or had heard of but never seen), we got to the point where Tim wanted to generalise the email type into "constrained strings". That was the point where metaclasses become necessary. It was then I realised that the approach we were using just wasn't going to be elegant, understandable, or maintainable without far more consideration than we could put into it (particularly when working to a tight deadline where the actual functionality added by the metaclass would be comparatively irrelevant to the operation of the system).
When I tried to explain why I was saying we should stop work I couldn't express the problem. I was basically saying that somehow the magic wouldn't let us get from here to there, but since it was all just magic I couldn't explain why we had to stop. That's the thing about magic, it's just supposed to work it's all about will, not mechanics.
You see, it's not that the approach wouldn't have worked in the narrow case of validating a form. It's that it would have been just an aglomeration of magic incantations with no internal logic or consistency. It would have been fantasy, rather than hard science fiction (all programming is a convenient fiction trying to represent the world through the abstraction of logic).
If your philosophy is not carefully considered; if your world-view does not properly account for all the little corner cases, and provide a set of rules the user can trust, then your philosophy will tend to undermine the user's ability to cope with the world in which they find themselves.
Creating a philosophy is not (generally) something that should be done quickly, or solely to solve a technical problem. Establishing a coherent, reasonable philosophy is a great deal of work. For solving a simple technical problem, the effort involved starts to look like a Rube Goldberg device. You don't need to redefine the fundamental constants of the universe to hit a nail on the head.
Anyway, as I was starting to write. I like teaching. I like philosophical introspection. Why am I not spending more of my life doing it?