Metasyntactic variable

From Wikipedia, the free encyclopedia
  (Redirected from Quux)
Jump to: navigation, search

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 to be applicable to the specific usage before compilation (translation to an executable). The words foo and bar are good examples as they are used in over 330 Internet Engineering Task Force Requests for Comments, which are documents explaining foundational internet technologies like HTTP(websites), 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]

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

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

Metasyntactic variables used commonly across all programming languages: foobar, foo, bar, baz, qux, quux, quuz, corge, grault, garply, waldo, fred, plugh, xyzzy, and thud.[1][3] Wibble, wobble, wubble, and flob are used in the UK.[4] And there are a reported blep, blah, and boop from Australia.[5][6]

A complete reference can be found in a MIT Press book titled: The Hacker's Dictionary.

Python[edit]

spam, ham, and eggs are the principal metasyntactic variables used in the Python programming language.[7] This is a reference to the comedy sketch Spam by Monty Python, the eponym of the language.[8]

R[edit]

The R programming language often adds norf to the list.[9]

French[edit]

In French, the words are toto and its derivatives, replacing o by other vowels: tata, titi, tutu... It may come from Toto who is the main character in many French jokes.[10][better source needed]

Japanese[edit]

In Japanese, the words hoge (ほげ)[11] and piyo (ぴよ) are commonly used, with other common words and variants being fuga" (ふが), "hogera (ほげら), and hogehoge (ほげほげ).[12][better source needed] 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.[12]

Usage Examples[edit]

C programming language[edit]

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;
}


Python programming language[edit]

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


Ruby programming language[edit]

In the following example the baz,  foo, and bar are  metasyntactic variables and lines beginning with # are comments.
# Declare the variable foo and set equal to 1
foo = 1

# Declare the variable bar and set equal to 2
bar = 2

# Declare the method (function) named baz, which prints the text 'Hello world'
def baz
   puts 'Hello world'
end

IETF Request for Comments[edit]

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 (cited in RFC 3092) contains for instance:

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

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

Teaching Concepts[edit]

This section includes bits of code which show how metasyntactic variables are used in teaching computer programming concepts.

C++[edit]

Function prototypes with different argument passing mechanisms:[17]

void foo(Fruit bar);
void foo(Fruit* bar);
void foo(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);


See also[edit]

References[edit]

  1. ^ a b c RFC 3092 (rfc3092) - Etymology of "Foo"
  2. ^ RFC-Editor.org
  3. ^ quuz. Retrieved November 18, 2016, from programming@ProgClub
  4. ^ wibble. (n.d.). Jargon File 4.4.7. Retrieved February 23, 2010, from [1]
  5. ^ blep. Retrieved November 18, 2016, from programming@ProgClub
  6. ^ blah, boop. Retrieved November 19, 2016, from programming@ProgClub
  7. ^ Python Tutorial
  8. ^ General Python FAQ
  9. ^ http://use-r.com/coursera-r-programming-week-2/
  10. ^ fr:Variable métasyntaxique#Toto
  11. ^ http://ejje.weblio.jp/content/hoge
  12. ^ a b メタ構文変数 (in Japanese)
  13. ^ Python Tutorial
  14. ^ General Python FAQ
  15. ^ http://sunsite.ualberta.ca/Documentation/Gnu/texinfo-4.0/html_chapter/texinfo_10.html
  16. ^ R. D. Tennent (2002). Specifying Software: A Hands-On Introduction. Cambridge University Press. pp. 36–37 and 210. ISBN 978-0-521-00401-5. 
  17. ^ John Mongan; Noah Kindler; Eric Giguere (2012). Programming Interviews Exposed: Secrets to Landing Your Next Job. John Wiley & Sons. p. 242. ISBN 978-1-118-28720-0. 

External links[edit]