2 ms·
Think 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 existi
by klibertp 12y ago
Think 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 :)