Search code examples
language-agnosticcode-generationmetaprogramming

What's the use of metaprogramming?


I've read:

and I confess some confusion at the purpose behind metaprogramming/code generation.

Does anyone have a concrete example of where they use metaprogramming/code generation? Even better would be an accompanying explanation of why it was better than an alternative.

edit: Would Thistle be considered metaprogramming?


Solution

  • Imagine a guy who builds cars. Say it's the same thing as using a computer.
    At some point he realizes he's always doing the same thing, more or less.
    So he builds factories to build cars, and it's much better. He's now programming !
    Nevertheless, once again, at some point, he realizes he's always doing the same thing, to some extent.
    Now he decides to build factories that build factories that build cars. That's metaprogramming.

    Metaprogramming is immensely powerful, but one glitch in the system makes all advantages turn into monster difficulties. So master it and use it... Or stay away !