On Thu, 27 Nov 2008 00:55:33 +0200, Hendrik van Rooyen wrote: > "Aaron Brady" <[EMAIL PROTECTED]> wrote: > > >>I don't know a clean, reliable way to structure a metaprogram though. >>Mine always turn out messy. > > Yes. > > Then another thing - it strikes me that any problem that can be solved > by metaprogramming, can be solved by putting similar code into a class > and instanciating an instance. > > Does anybody know if this is true?
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. 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. 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. -- Steven -- http://mail.python.org/mailman/listinfo/python-list