Skip to main content

Metaprogramming

Metaprogramming is a programming technique in which computer programs have the ability to treat programs as data. It means a program can be designed to read, generate, analyze or transform other programs, or even itself while running. In some cases, it allows programmers to minimize the number of lines of code to express a solution, thus reducing the development time. It also allows programs greater flexibility to efficiently handle new situations without recompilation. Metaprogramming can be used to move computations from run-time to compile-time, to generate code using compile time computations, and to enable self-modifying code. The language in which the metaprogram is written is called the metalanguage. The language of the programs that are manipulated is called the object language. The ability of a programming language to be its own metalanguage is called reflection or reflexivity. Reflection is a valuable language feature to facilitate metaprogramming.