Getting in to metaprogramming

Hendrik van Rooyen mail at microcorp.co.za
Thu Nov 27 05:41:47 CET 2008


 "Steven D'Aprano" <steau> wrote:

> 
> Well, I don't know about "any problem". And it's not so much about 
> whether metaprograms can solve problems that can't be solved by anything 
> else, as whether metaprograms can solve problems more effectively than 
> other techniques.
> 
> If you include factory functions, class factories, the builder design 
> pattern, metaclasses, etc. as "metaprogramming", then I use it all the 
> time, and find it an excellent technique to use.
> 
> But if you mean using a Python program to generate Python source code, 
> then I can't think of any time I used it. Which doesn't mean that others 
> don't find it helpful, only that I haven't yet.

I am using the term in the restricted sense of Python writing Python source.

Given that, can anybody think of an example that you could not do with 
a class?  (excepting the "stored procedure" aspect)

Or can I claim a new a new meta - rule - I would call it van Rooyen's folly...

> 
> Thinking further back, when I was young and programming in Apple's 
> Hypercard 4GL, I used to frequently use Hypercard scripts to generate new 
> Hypercard scripts. That was to work around the limitations of the 
> scripting language.

What sort of stuff did you do, and would having had simple OO available
have rendered it unnecessary?

> 
> I don't think metaprogramming in the limited sense (programs to output 
> source code) is a bad idea, but I do think that there are probably better 
> alternatives in a language like Python.
> 
> 
True. No argument here - I was just wondering if the relationship holds.

- Hendrik




More information about the Python-list mailing list