ArticleslgStudy

computer science

Metasyntactic variable

Metasyntactic variable is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Metasyntactic variable rather than just read about it. In short: 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.

Metasyntactic variable — main illustration
Metasyntactic variable — illustration

Key takeaways

  • Metasyntactic variable belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Metasyntactic variable to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Metasyntactic variable from memory before moving on to harder problems.

Reference excerpt

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. For example, foo and bar are used in over 330 Internet Engineering Task Force Requests for Comments, the documents which define foundational internet technologies like HTTP (web), 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 Since English is the foundation language or lingua franca of most computer programming languages, variables that originate in English are commonly seen even in programs and examples of programs written for other spoken-language audiences. The variables used in a particular context may depend on subcultures that develop around programming languages.

General usage Metasyntactic variables used commonly across all programming languages include foobar, foo, bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, and thud. Two of these words, plugh and xyzzy, are taken from the game Colossal Cave Adventure. A fuller reference can be found in The Hacker's Dictionary from MIT Press.

Japanese In Japanese, the words hoge (ほげ) and fuga (ふが) are commonly used, with other common words and variants being piyo (ぴよ), hogera (ほげら), and hogehoge (ほげほげ). 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 word toto 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.

Turkish In Turkey, the words hede and hödö (usually spelt hodo due to ASCII-only naming constraints of programming languages) are well-known metasyntactic variables that stem from popular humorous cartoon magazines of the 90's like LeMan. The words do not mean anything, and are used for precisely that reason. The terms were popularized more widely by the actor and stand-up comedian Cem Yılmaz in the late 90's and early 2000's.

Italian In Italian software programming culture, it is common to encounter names of Walt Disney characters (as found in the Italian versions of the shows) being used as variables. These names often appear in pseudo-code, are referenced in software engineering classes, and are commonly employed when explaining algorithms to colleagues. Among the most frequently used are "pippo" (Goofy), "pluto", and "paperino" (Donald Duck).

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.

C++

Function prototypes with examples of different argument passing mechanisms:

Example showing the function overloading capabilities of the C++ language

Python Spam, 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.

IETF Requests for Comments 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. Here is an example from the official IETF document explaining the e-mail protocols (from RFC 772 - cited in RFC 3092):

All is well; now the recipients can be specified.

S: MRCP TO:<Foo@Y> <CRLF> R: 200 OK

S: MRCP TO:<Raboof@Y> <CRLF> R: 553 No such user here

S: MRCP TO:<bar@Y> <CRLF> R: 200 OK

S: MRCP TO:<@Y,@X,fubar@Z> <CRLF> 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".

(The documentation for texinfo emphasizes the distinction between metavariables and mere variables used in a programming language being documented in some texinfo file as: "Use the @var command to indicate metasyntactic variables. A metasyntactic variable is something that stands for another piece of text. For example, you should use a metasyntactic variable in the documentation of a function to describe the arguments that are passed to that function. Do not use @var for the names of particular variables in programming languages. These are specific names from a program, so @code is correct for them.") 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.

Example data

SQL It is common to use the name ACME in example SQL databases and as a 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.

See also Metavariable (logic) xyzzy Alice and Bob John Doe Fnord Free variables and bound variables Gadget Lorem ipsum Nonce word Placeholder name Widget Smurf

References

External links Definition of metasyntactic variable, with examples. Examples of metasyntactic variables used in Commonwealth Hackish, such as wombat. Variable "foo" and Other Programming Oddities

Worked examples

Example 1 — a first encounter with Metasyntactic variable

Start with the simplest possible case. Write down what Metasyntactic variable claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Metasyntactic variable before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Metasyntactic variable ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Metasyntactic variable

In research
Metasyntactic variable appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Metasyntactic variable in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Metasyntactic variable is common in secondary-school and first-year university syllabi. It links to neighbouring topics Metalogic, Placeholders, Syntax (logic), so understanding it makes those chapters shorter.
In everyday life
Look for Metasyntactic variable outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Metasyntactic variable in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Metasyntactic variable means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Metasyntactic variable out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Metasyntactic variable in simple terms?

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.

Why does Metasyntactic variable matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Metasyntactic variable?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Metasyntactic variable.

Tags

  • Metalogic
  • Placeholders
  • Syntax (logic)
  • Variable (computer science)

Keep exploring