Metaprogramming (Programming)

Metaprogramming is the writing of programs that write or manipulate other programs (or themselves) as their data or that do part of the work that is otherwise done at runtime during compile time. This allows programmers to produce a larger amount of code and get more done in the same amount of time as they would take to write all the code manually. A simple example of a metaprogram is this bash script:
 
  1. !/bin/bash
  2. metaprogram
echo "#!/bin/bash" > program for ((I=1;I<=992;I++)) do
         echo "echo $I" >> program 
done chmod +x program
This script (or program) generates a new 993 line program which prints out the numbers 1-992. This is only an illustration on how to use code to write more code, not the most efficient way to print out a list of numbers. Nonetheless, a good programmer can write and execute this metaprogram in just a couple of minutes, and will have generated exactly 1000 lines of code in that amount of time.
  • The most common metaprogramming tool is a compiler which allows a programmer to write a relatively short program in a high-level language and uses it to write an equivalent assembly language or machine language program. This generally saves a good deal of time compared to writing the machine language program directly.
  • Another still fairly common example of metaprogramming might be found in the use of lex (see also: flex) and yacc (see also: bison), which are used to generate compilers and interpreters.
  • A Quine is a special kind of metaprogram that has its own source as its output.
Reflection is a valuable language feature for facilitating metaprogramming. Having the programming language itself as a first class data type (as in Lisp) is also very useful.

See also

External links

 

<< PreviousWord BrowserNext >>
suncheon
longford
bellaire, kansas
county longford
icod de los vinos
county westmeath
leon askin
estates of the realm
boseong county
damyang county
irish vehicle registration plates
joseph martin kraus
annay sous lens
nitty gritty
kang the conqueror
gangjin county
v. p. kale
winnipeg international airport
skint records
goheung county
1975 world series
stoford
greenberg
gokseong county
stilt sandpiper
shi naian
ford festiva
southland conference
archibald lampman
denominazione di origine controllata
murder triangle
former supreme court building
john runciman
croagh patrick
ezra taft benson
pentangle (band)
the city and the pillar
william friedkin
pentangle
alan davidson
the great rock 'n' roll swindle
ringwood
figlet
stoke mandeville hospital