Metasyntactic variable: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
imported>PrimeBOT
m Task 24: template replacement following an RFD
 
imported>ButterCashier
Reverting edit(s) by 105.99.166.118 (talk) to rev. 1309199976 by W.andrea: non-constructive (RW 16.1)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Short description|Placeholder term used in computer science}}
{{Short description|Placeholder term used in computer science}}
{{About|metasyntactic variables in computer science and programming|metasyntactic variables as used in formal logic|Metavariable (logic)|usage in spoken languages|Placeholder name}}
{{About|computer science and programming|formal logic|Metavariable (logic)|spoken languages|Placeholder name}}
A '''metasyntactic variable''' is a specific word or set of words identified as a [[placeholder name|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, [[Foobar|''foo'' and ''bar'']] are used in over 330 [[Internet Engineering Task Force]] [[Request for Comments|Requests for Comments]], the documents which define foundational internet technologies like [[HTTP]] (web), [[TCP/IP]], and [[email]] [[Communications protocol|protocol]]s.<ref name="RFC3092">{{cite IETF|rfc=3092|title=Etymology of "Foo"|first1=Donald E.|last1=((Eastlake 3rd))|first2=Carl-Uno|last2=Manros|first3=Eric S.|last3=Raymond}}</ref><ref>{{Cite web|url=https://www.rfc-editor.org/retrieve/|title=Document Retrieval|work=RFC Editor}}</ref>
A '''metasyntactic variable''' is a specific word or set of words identified as a [[placeholder name|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, [[Foobar|''foo'' and ''bar'']] are used in over 330 [[Internet Engineering Task Force]] [[Request for Comments|Requests for Comments]], the documents which define foundational internet technologies like [[HTTP]] (web), [[TCP/IP]], and [[email]] [[Communications protocol|protocol]]s.<ref name="RFC3092">{{cite IETF|rfc=3092|title=Etymology of "Foo"|first1=Donald E.|last1=((Eastlake 3rd))|first2=Carl-Uno|last2=Manros|first3=Eric S.|last3=Raymond}}</ref><ref>{{Cite web|url=https://www.rfc-editor.org/retrieve/|title=Document Retrieval|work=RFC Editor}}</ref>


Line 27: Line 27:


===Italian===
===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).<ref>{{Cite web|url=http://www.catb.org/jargon/html/M/metasyntactic-variable.html|title=The Jargon File - metasyntactic variable|website=www.catb.org/}}</ref>
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).<ref>{{Cite web|url=http://www.catb.org/jargon/html/M/metasyntactic-variable.html|title=The Jargon File - metasyntactic variable|website=www.catb.org/}}</ref>


== Usage examples ==
== Usage examples ==
Line 131: Line 131:
*[http://blog.codinghorror.com/variable-foo-and-other-programming-oddities/ Variable "foo" and Other Programming Oddities]
*[http://blog.codinghorror.com/variable-foo-and-other-programming-oddities/ Variable "foo" and Other Programming Oddities]


[[Category:Placeholder names]]
[[Category:Placeholders]]
[[Category:Metalogic]]
[[Category:Metalogic]]
[[Category:Variable (computer science)]]
[[Category:Variable (computer science)]]
[[Category:Syntax (logic)]]
[[Category:Syntax (logic)]]

Latest revision as of 09:44, 24 September 2025

Template:Short description Script error: No such module "about". 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.[1][2]

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.[1]Script error: No such module "Unsubst".

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, Template:Not a typo, Template:Not a typo, Template:Not a typo, Template:Not a typo, Template:Not a typo, Template:Not a typo, Template:Not a typo, Template:Not a typo, [[xyzzy (computing)|Template:Not a typo]], and thud.[1][3] Two of these words, plugh and xyzzy, are taken from the game Colossal Cave Adventure.[4]

A fuller reference can be found in The Hacker's Dictionary from MIT Press.

Japanese

In Japanese, the words Template:Transliteration (ほげ)[5] and Template:Transliteration (ふが) are commonly used, with other common words and variants being Template:Transliteration (ぴよ), Template:Transliteration (ほげら), and Template:Transliteration (ほげほげ).[6]Template:Circular reference The origin of Template:Transliteration as a metasyntactic variable is not known, but it is believed to date to the early 1980s.[6]

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.Script error: No such module "Unsubst".

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.[7]

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).[8]

Usage examples

File:Metasyntactic Variable FOO in Shell.png
A screenshot of a metasyntactic variable FOO assigned and echoed in an interactive shell session.

C

Script error: No such module "Labelled list hatnote". 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(void)
{
   // Declare the variable bar and set the value to 1
   int bar = 1;

   return bar;
}

C++

Script error: No such module "Labelled list hatnote". Function prototypes with examples of different argument passing mechanisms:[9]

void Foo(Fruit bar);
void Foo(Fruit* bar);
void Foo(const Fruit& bar);

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

void Foo(int bar);
void Foo(int bar, int baz);
void Foo(int bar, int baz, int qux);

Python

Spam, ham, and eggs are the principal metasyntactic variables used in the Python programming language.[10] This is a reference to the famous comedy sketch, "Spam", by Monty Python, the eponym of the language.[11] 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

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."[12])

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.[13]

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.[14][15][16]

See also

References

Template:Reflist

External links

  1. a b c Template:Cite IETF
  2. Script error: No such module "citation/CS1".
  3. Template:Cite mailing list
  4. Script error: No such module "citation/CS1".
  5. Script error: No such module "citation/CS1".
  6. a b メタ構文変数 Template:In lang
  7. Script error: No such module "citation/CS1".
  8. Script error: No such module "citation/CS1".
  9. Script error: No such module "citation/CS1".
  10. Script error: No such module "citation/CS1".
  11. Script error: No such module "citation/CS1".
  12. Script error: No such module "citation/CS1".
  13. Script error: No such module "citation/CS1".
  14. Script error: No such module "citation/CS1".
  15. Script error: No such module "citation/CS1".
  16. Script error: No such module "citation/CS1".