4 ms·
Yeah, I don't get the unity of it all, or why it's called "metaprogramming". The examples always look like they fall into one of two categories: 1. super-easy
by hyperpape 12y ago
Yeah, I don't get the unity of it all, or why it's called "metaprogramming". The examples always look like they fall into one of two categories:
1. super-easy development of new parsers/compilers (lisp macros)
2. shenanigans with dynamicism and first class functions.
Both of those are cool! But I can't figure out what they have to do with each other, other than that you don't get much of that sort of thing in Java/C.
- klibertp 12y agoThink about it this way: what can you do to code, with code? You can create new code (simple macros, emitting optimized bytecode, etc.) or you can modify existing code (self-modifying code, instrumentation (example: Quasar and Pulsar in Java http://blog.paralleluniverse.co/2013/05/02/quasar-pulsar/ http://blog.paralleluniverse.co/2013/05/02/quasar-pulsar/), etc.) and that's about it. Exactly how you go on about this varies wildly depending on what tools you have at your disposal, but the unifying thing about all of them is that you're writing code which acts on other code, for some (rather fuzzy) definitions of "code" and "acting on". One nice example of modifying code on the fly I just remembered is goto decorator in Python: http://code.activestate.com/recipes/576944-the-goto-decorator/ http://code.activestate.com/recipes/576944-the-goto-decorato... As for code generation, if I recall correctly, Salt (http://docs.saltstack.com/en/latest/ http://docs.saltstack.com/en/latest/) uses YAML and Jinja2 to generate shell scripts. These are very different techniques, but the thing they have in common is that they manipulate code, which makes them both examples of meta-programming. At least that's how I understand the term :)