Misplaced Pages

Metasyntactic variable: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editContent deleted Content addedVisualWikitext
Revision as of 19:25, 29 January 2008 editFox (talk | contribs)Administrators33,217 edits Fixing links to disambiguation pages using AWB← Previous edit Latest revision as of 09:26, 19 December 2024 edit undo81.14.168.149 (talk) German: I've been a programmer for 20+ years, teaching in academics the recent 5. I've yet to encounter a single class named "Klaus". Most programmers (I've met and talked to) stick to english variable- and class- names, as most german words either too long or complicated and using a unified language helps with multi-cultural teams. IT / CS is english.Tags: section blanking Visual edit 
(502 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
{{Short description|Placeholder term used in computer science}}
A '''metasyntactic variable''' ({{pronEng|ˌmɛtəsɪnˈtækt<s>ɪ</s>k ˈvɛəriəbl}}) is a ] or an ] term commonly used to denote the subject matter under discussion or an arbitrary member of a class of things under discussion. The term originates from ] and other technical contexts, and is commonly used in examples by ]s and ]s. The use of a metasyntactic variable is helpful in freeing a programmer from creating a logically named variable, although the invented term may also become sufficiently popular and enter the language as a ]. The word ] is the ] example.<ref name="RFC3092">http://www.faqs.org/rfcs/rfc3092.html</ref>
{{About|metasyntactic variables in computer science and programming|metasyntactic variables as used in formal logic|Metavariable (logic)|usage in spoken languages|Placeholder name}}
A '''metasyntactic variable''' is a specific word or set of words identified as a ] in ] and specifically ]. These words are commonly found in ] and are intended to be modified or substituted before real-world usage. For example, ] are used in over 330 ] ], the documents which define foundational internet technologies like ] (web), ], and ] ]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>


By mathematical ], a ] variable is a word that is a ] for other words, just as in ] letters are used as variables for ]s.<ref name="RFC3092"/>
Any word can be used as a metasyntactic variable however "nonsense words" are commonly used to denote that they are being used as such. The same concept is employed in other fields where it is expressed by terms such as ''schematic variable'' (see ]).


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.
==Explanation of the concept==
===By dissection the word===


==Common metasyntactic variables==
:* ']' means information about, more comprehensive, or transcending.
Since English is the foundation language or ] 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.
:* ']' means the grammatical arrangement of words or The grammatical rules of a programming language.
:* ']' means something that can assume a value, or something likely to vary.


The variables used in a particular context may depend on subcultures that develop around ]s.
:So we have a word that '''transcends grammar and can assume a value'''.
:Or one that is '''more comprehensive than grammatical arrangement and is likely to vary'''.


===By mathematical analogy=== ===General usage===
Metasyntactic variables used commonly across all programming languages include '']'', ''foo'', ''bar'', ''baz'', ''{{not a typo|qux}}'', ''{{not a typo|quux}}'', ''{{not a typo|corge}}'', ''{{not a typo|grault}}'', ''{{not a typo|garply}}'', ''{{not a typo|waldo}}'', ''{{not a typo|fred}}'', ''{{not a typo|]}}'', '']'', and ''thud''.<ref name="RFC3092"/><ref>{{cite mailing list|title=Metasyntactic variable|first=Stuart|last=Laughlin|date=November 18, 2016|access-date=November 18, 2016|url=https://www.progclub.org/pipermail/programming/2016-November/002305.html|mailing-list=programming@ProgClub|url-status=dead|archive-url=https://web.archive.org/web/20221202085628/https://www.progclub.org/pipermail/programming/2016-November/002305.html|archive-date=December 2, 2022}}</ref> Two of these words, ''plugh'' and ''xyzzy'', are taken from the game '']''.<ref>{{cite web |url=https://jerz.setonhill.edu/if/crowther/advdat.77-03-11 |title=advdat.77-03-11 |last=Crowther |first=Will |date=1977-03-11 |website= Colossal Cave Adventure Source Code |publisher=Dennis G. Jerz |access-date=2024-02-28}}</ref>
:A metasyntactic variable is as a ] that is a ] for other words, just as in ] letters are used as variables for numbers.<ref name="RFC3092">http://www.faqs.org/rfcs/rfc3092.html</ref>


A fuller reference can be found in '']'' from ].
==Words commonly used as metasyntactic variables==
A "standard list of metasyntactic variables used in syntax examples" is: foo, bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud.<ref name="RFC3092">http://www.faqs.org/rfcs/rfc3092.html</ref> The word ''foo'' occurs in over 330 ]s and ''bar'' occurs in over 290.{{Fact|date=January 2008}}<!-- <ref>http://www.rfc-editor.org/download.html</ref> -->


===Japanese===
'']'' is used in one section of a tutorial on the ] by ]. Here, he illustrates the use of the ''extern'' ]:<ref>http://www.lysator.liu.se/c/bwk-tutor.html</ref>
In Japanese, the words {{transl|ja|hoge}} (ほげ)<ref>{{Cite web|url=https://ejje.weblio.jp/content/hoge|title=hogeの意味・使い方 - 英和辞典 Weblio 辞書|website=ejje.weblio.jp}}</ref> and {{transl|ja|fuga}} (ふが) are commonly used, with other common words and variants being {{transl|ja|piyo}} (ぴよ), {{transl|ja|hogera}} (ほげら), and {{transl|ja|hogehoge}} (ほげほげ).<ref name="ja">] {{in lang|ja}}</ref>{{Circular reference|date=September 2017}} The origin of {{transl|ja|hoge}} as a metasyntactic variable is not known, but it is believed to date to the early 1980s.<ref name="ja" />
<pre>
Second, at the beginning of any file
that contains functions needing a variable whose definition is in some other file,
put in an extern declaration, outside of any function:


===French===
extern int foo;
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 ].{{CN|date=February 2022}}


===Turkish===
f1( ) { ... }
In Turkey, the words ''hede'' and ''hödö'' (usually spelt ''hodo'' due to ]-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 ] in the late 90's and early 2000's.<ref>{{Cite book |url=https://books.google.com/books?id=dRxdDwAAQBAJ&dq=hede+h%C3%B6d%C3%B6&pg=PA12 |title=LeMan Dergisi 1376. Sayı |publisher=Lm Basin Yayin Ltd.şti. |language=tr}}</ref>
etc.
</pre>


===Italian===
], ], and ] are the canonical metasyntactic variables used in the ].<ref>http://docs.python.org/tut/</ref> This is a reference to the famous comedy sketch, '']'', by ], the namesake of the language.<ref>http://www.python.org/doc/faq/general/#why-is-it-called-python</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>
In this extract from the Python tutorial showing the use of ]s,<ref>http://docs.python.org/tut/node5.html</ref> ''STRING'' is a metasyntactic variable.
<pre>
Some examples:


== Usage examples ==
# this is the first comment
]
SPAM = 1 # and this is the second comment
# ... and now a third!
STRING = "# This is not a comment."
</pre>


===C===
''Arfle'', ''barfle'', and ''gloop'', which are commonly used by those with a ] or ] background, originated as the response of the parser of a ] BBC Micro ] to input it didn't understand.<ref>http://www.everything2.com/index.pl?node_id=550120</ref> An example of these can be seen in this ] bug report, along with other interesting metasyntactic variables.<ref>http://gcc.gnu.org/ml/gcc-bugs/2000-02/msg00244.html</ref>
{{See also|C programming language}}
The author of this ] has written an example program for the sole purpose of demonstrating the ]. He provides "a ] which lays out some ]s" using names that are arbitrary, but ] required:
In the following example the function name <code>foo</code> and the variable name <code>bar</code> are both metasyntactic variables. Lines beginning with <code>//</code> are comments.
<pre>
<syntaxhighlight lang="cpp">
...
// The function named foo
struct Side
int foo(void)
{ {
// Declare the variable bar and set the value to 1
virtual ~Side ();
virtual void Arfle (); int bar = 1;

virtual void Barfle ();
return bar;
virtual void Gloop ();
}
virtual void Glorp ();
</syntaxhighlight>
virtual void Glump ();

virtual void Bogus ();
===C++===
};
{{See also|C++}}
...
Function prototypes with examples of different ] mechanisms:<ref name="MonganKindler2012">{{cite book|first1=John|last1=Mongan|first2=Noah|last2=Kindler|first3=Eric|last3=Giguere|title=Programming Interviews Exposed: Secrets to Landing Your Next Job|url=https://books.google.com/books?id=GQE4r2e5fAsC&pg=PA242|year=2012|publisher=John Wiley & Sons|isbn=978-1-118-28720-0|page=242}}</ref>
</pre>
<syntaxhighlight lang="cpp">
void Foo(Fruit bar);
void Foo(Fruit* bar);
void Foo(const Fruit& bar);
</syntaxhighlight>

Example showing the ] capabilities of the C++ language
<syntaxhighlight lang="cpp">
void Foo(int bar);
void Foo(int bar, int baz);
void Foo(int bar, int baz, int qux);
</syntaxhighlight>

===Python===
], ], and ] are the principal metasyntactic variables used in the ].<ref>{{Cite web|url=https://docs.python.org/3/tutorial/|title=The Python Tutorial — Python 3.8.1 documentation|website=docs.python.org}}</ref> This is a reference to the famous comedy sketch, "]", by ], the eponym of the language.<ref>{{Cite web |date=2021-09-04 |title=General Python FAQ — Python 3.9.7 documentation |url=https://docs.python.org/3/faq/general.html |url-status=live |archive-url=https://web.archive.org/web/20210826153036/https://docs.python.org/3/faq/general.html#why-is-it-called-python |archive-date=2021-08-26 |access-date=2021-09-05 |website=docs.python.org |publisher=Python Software Foundation |at=Why is it called Python?}}</ref>
In the following example <code>spam</code>, <code>ham</code>, and <code>eggs</code> are metasyntactic variables and lines beginning with <code>#</code> are comments.
<syntaxhighlight lang="python">
# Define a function named spam
def spam():

# Define the variable ham
ham = "Hello World!"

# Define the variable eggs
eggs = 1

return
</syntaxhighlight>

===IETF Requests for Comments===
Both the ] ]s and ]s are rendered in ], 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 ] document explaining the ] 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 ] in programming languages. These are specific names from a program, so @code is correct for them."<ref>{{cite web |url=http://sunsite.ualberta.ca/Documentation/Gnu/texinfo-4.0/html_chapter/texinfo_10.html |title=Marking Words and Phrases |work=Texinfo 4.0. The GNU Documentation Format|access-date=2012-11-25 |url-status=dead |archive-url=https://web.archive.org/web/20091106004856/http://sunsite.ualberta.ca/Documentation/Gnu/texinfo-4.0/html_chapter/texinfo_10.html |archive-date=2009-11-06 }}</ref>)

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 ] symbols in ] where the nonterminals on the right of a production can be substituted by different instances.<ref name="Tennent2002">{{cite book|author=R. D. Tennent|title=Specifying Software: A Hands-On Introduction|year=2002|publisher=Cambridge University Press|isbn=978-0-521-00401-5|pages=36–37 and 210}}</ref>

==Example data==
===SQL===
It is common to use the name ] in example ] ]s 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 ] and ].<ref name="Kriegel 2008 p.">{{cite book | last=Kriegel | first=Alex | title=SQL bible | publisher=Wiley | publication-place=Indianapolis, Ind | year=2008 | isbn=978-0-470-22906-4 | oclc=402446308 }}</ref><ref name="Ruel 2014 p.">{{cite book | last=Ruel | first=Chris | title=Oracle 12c for dummies | publisher=John Wiley & Sons | publication-place=Hoboken, NJ | year=2014 | isbn=978-1-118-74531-1 | oclc=870334544 | language=da }}</ref><ref>{{Cite web|url=https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/work-with-data-in-asp-net-core-apps|title=Work with data in ASP.NET Core Apps|website=docs.microsoft.com}}</ref>


==See also== ==See also==
*] *]
*]
*]
*]
*]
*]
*]
*]
*] *]
*] *]
*]
*]
*]
*'']''
*]
*]
*]
*]


==References== ==References==
{{Reflist}}
<references />


==External links== ==External links==
* *
* used in ''] ]'', such as ''wombat''. * used in ''] Hackish'', such as ''wombat''.
* *


] ]
]

] ]
]
]
]
]
]
]
]
]
]
]

Latest revision as of 09:26, 19 December 2024

Placeholder term used in computer science This article is about metasyntactic variables in computer science and programming. For metasyntactic variables as used in formal logic, see Metavariable (logic). For usage in spoken languages, see Placeholder name.

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

A screenshot of a metasyntactic variable FOO assigned and echoed in an interactive shell session.

C

See also: C programming language

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++

See also: C++

Function prototypes with examples of different argument passing mechanisms:

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

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

References

  1. ^ Eastlake 3rd, Donald E.; Manros, Carl-Uno; Raymond, Eric S. Etymology of "Foo". doi:10.17487/RFC3092. RFC 3092.
  2. "Document Retrieval". RFC Editor.
  3. Laughlin, Stuart (November 18, 2016). "Metasyntactic variable". programming@ProgClub (Mailing list). Archived from the original on December 2, 2022. Retrieved November 18, 2016.
  4. Crowther, Will (1977-03-11). "advdat.77-03-11". Colossal Cave Adventure Source Code. Dennis G. Jerz. Retrieved 2024-02-28.
  5. "hogeの意味・使い方 - 英和辞典 Weblio 辞書". ejje.weblio.jp.
  6. ^ メタ構文変数 (in Japanese)
  7. LeMan Dergisi 1376. Sayı (in Turkish). Lm Basin Yayin Ltd.şti.
  8. "The Jargon File - metasyntactic variable". www.catb.org/.
  9. Mongan, John; Kindler, Noah; Giguere, Eric (2012). Programming Interviews Exposed: Secrets to Landing Your Next Job. John Wiley & Sons. p. 242. ISBN 978-1-118-28720-0.
  10. "The Python Tutorial — Python 3.8.1 documentation". docs.python.org.
  11. "General Python FAQ — Python 3.9.7 documentation". docs.python.org. Python Software Foundation. 2021-09-04. Why is it called Python?. Archived from the original on 2021-08-26. Retrieved 2021-09-05.
  12. "Marking Words and Phrases". Texinfo 4.0. The GNU Documentation Format. Archived from the original on 2009-11-06. Retrieved 2012-11-25.
  13. R. D. Tennent (2002). Specifying Software: A Hands-On Introduction. Cambridge University Press. pp. 36–37 and 210. ISBN 978-0-521-00401-5.
  14. Kriegel, Alex (2008). SQL bible. Indianapolis, Ind: Wiley. ISBN 978-0-470-22906-4. OCLC 402446308.
  15. Ruel, Chris (2014). Oracle 12c for dummies (in Danish). Hoboken, NJ: John Wiley & Sons. ISBN 978-1-118-74531-1. OCLC 870334544.
  16. "Work with data in ASP.NET Core Apps". docs.microsoft.com.

External links

Categories: