A metasyntactic variable is a specific word or set of words identified as a placeholder in computer science and specifically computer programming. These words are commonly found in source code and are intended to be modified or substituted before real-world usage. The words foo and bar are good examples as they are used in over 330 Internet Engineering Task ForceRequests for Comments, the documents which define foundational internet technologies like HTTP, TCP/IP, and email protocols. By mathematical analogy, a metasyntactic variable is a word that is a variable for other words, just as in algebra letters are used as variables for numbers. Metasyntactic variables are used to name entities such as variables, functions, and commands whose exact identity is unimportant and serve only to demonstrate a concept, which is useful for teaching programming.
Common metasyntactic variables
Due to English being the foundation-language, or lingua franca, of most computer programming languages these variables are commonly seen even in programs and examples of programs written for other spoken-language audiences. The typical names may depend however on the subculture that has developed around a given programming language.
General usage
Metasyntactic variables used commonly across all programming languages include foobar, foo, bar, baz, qux, quux, quuz, corge, grault, garply, waldo, fred, plugh, xyzzy, and thud; several of these words are references to the gameColossal Cave Adventure. Wibble, wobble, wubble, and flob are also used in the UK. A complete reference can be found in a MIT Press book titled The Hacker's Dictionary.
Japanese
In Japanese, the wordshoge and piyo are commonly used, with other common words and variants being fuga, hogera, and hogehoge. Note that -ra is a pluralizing ending in Japanese, and reduplication is also used for pluralizing. The origin of hoge as a metasyntactic variable is not known, but it is believed to date to the early 1980s.
French
In France, the wordtoto is widely used, with variants tata, titi, tutu as related placeholders. One commonly-raised source for the use of toto is a reference to the stock character used to tell jokes with Tête à Toto.
Usage examples
C
In the following example the function name foo and the variable name bar are both metasyntactic variables. Lines beginning with // are comments. // The function named foo int foo
Python
, ham, and eggs are the principal metasyntactic variables used in the Python programming language. This is a reference to the famous comedy sketch, "Spam", by Monty Python, the eponym of the language. In the following example spam, ham, and eggs are metasyntactic variables and lines beginning with # are comments.
Define a function named spam
def spam: # Define the variable ham ham = "Hello World!" # Define the variable eggs eggs = 1 return
Both the IETF RFCs and computer programming languages are rendered in plain text, making it necessary to distinguish metasyntactic variables by a naming convention, since it would not be obvious from context. Plain text example: RFC 772 contains for instance: All is well; now the recipients can be specified. S: MRCP TO: R: 200 OK S: MRCP TO: R: 553 No such user here S: MRCP TO: R: 200 OK S: MRCP TO:<@Y,@X,fubar@Z> R: 200 OK Note that the failure of "Raboof" has no effect on the storage of mail for "Foo", "bar" or the mail to be forwarded to "fubar@Z" through host "X". Another point reflected in the above example is the convention that a metavariable is to be uniformly substituted with the same instance in all its appearances in a given schema. This is in contrast with nonterminal symbols in formal grammars where the nonterminals on the right of a production can be substituted by different instances.
Teaching concepts
This section includes bits of code which show how metasyntactic variables are used in teaching computer programming concepts.
C++
Function prototypes with examples of different argument passing mechanisms: void Foo; void Foo; void Foo;
It is common to use the name ACME in example SQL Databases and as placeholder company-name for the purpose of teaching. The term 'ACME Database' is commonly used to mean a training or example-only set of database data used solely for training or testing. ACME is also commonly used in documentation which shows SQL usage examples, a common practice with in many educational texts as well as technical documentation from companies such as Microsoft and Oracle.