Metasyntactic variable

Last updated

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]

Contents

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

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, corge, grault, garply, waldo, fred, plugh , xyzzy , and thud. [1] [3] Two of these words, plugh and xyzzy, are taken from the game Colossal Cave Adventure . [4]

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

Japanese

In Japanese, the words hoge (ほげ) [5] and fuga (ふが) are commonly used, with other common words and variants being piyo (ぴよ), hogera (ほげら), and hogehoge (ほげほげ). [6] [ circular reference ] The origin of hoge 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.[ citation needed ]

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 stemmed from popular humorous cartoon magazines of the 90's like LeMan. The words do not mean anything, and specifically used in place of things that do not mean anything. The terms have been popularized to the masses by the actor and stand-up comedian Cem Yılmaz in the late 90's and early 2000's. [7]

Italian

In the Italian software programming culture, it is common to encounter names of Walt Disney characters 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

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

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 foointfoo(void){// Declare the variable bar and set the value to 1intbar=1;returnbar;}

C++

Function prototypes with examples of different argument passing mechanisms: [9]

voidFoo(Fruitbar);voidFoo(Fruit*bar);voidFoo(constFruit&bar);

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

voidFoo(intbar);voidFoo(intbar,intbaz);voidFoo(intbar,intbaz,intqux);

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 spamdefspam():# Define the variable hamham="Hello World!"# Define the variable eggseggs=1return

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

Related Research Articles

The terms foobar, foo, bar, baz, and others are used as metasyntactic variables and placeholder names in computer programming or computer-related documentation. They have been used to name entities such as variables, functions, and commands whose exact identity is unimportant and serve only to demonstrate a concept. The style guide for Google developer documentation recommends against using them as example project names because they are unclear and can cause confusion.

In computing, a namespace is a set of signs (names) that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified.

In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment. The environment is a mapping associating each free variable of the function with the value or reference to which the name was bound when the closure was created. Unlike a plain function, a closure allows the function to access those captured variables through the closure's copies of their values or references, even when the function is invoked outside their scope.

Programming style, also known as coding style or code style, is a set of rules or guidelines that governs the layout of source code. Programming style may also refer an quality aspect of code that is interpreted subjectively.

A string literal or anonymous string is a literal for a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally "bracketed delimiters", as in x = "foo", where "foo" is a string literal with value foo. Methods such as escape sequences can be used to avoid the problem of delimiter collision and allow the delimiters to be embedded in a string. There are many alternate notations for specifying string literals especially in complicated cases. The exact notation depends on the programming language in question. Nevertheless, there are general guidelines that most modern programming languages follow.

In computer science, a union is a value that may have any of several representations or formats within the same position in memory; that consists of a variable that may hold such a data structure. Some programming languages support special data types, called union types, to describe such values and variables. In other words, a union type definition will specify which of a number of permitted primitive types may be stored in its instances, e.g., "float or long integer". In contrast with a record, which could be defined to contain both a float and an integer; in a union, there is only one value at any given time.

In computer programming, named parameters, named-parameter arguments, named arguments or keyword arguments refer to a computer language's support for function calls to clearly associate each argument with a given parameter within the function call.

In class-based, object-oriented programming, a constructor is a special type of function called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.

In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures. Some programming language theorists require support for anonymous functions as well. In languages with first-class functions, the names of functions do not have any special status; they are treated like ordinary variables with a function type. The term was coined by Christopher Strachey in the context of "functions as first-class citizens" in the mid-1960s.

In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.

In mathematics and in computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages.

In object-oriented programming, a destructor is a method which is invoked mechanically just before the memory of the object is released. It can happen when its lifetime is bound to scope and the execution leaves the scope, when it is embedded in another object whose lifetime ends, or when it was allocated dynamically and is released explicitly. Its main purpose is to free the resources which were acquired by the object during its life and/or deregister from other entities which may keep references to it. Use of destructors is needed for the process of Resource Acquisition Is Initialization (RAII).

The C and C++ programming languages are closely related but have many significant differences. C++ began as a fork of an early, pre-standardized C, and was designed to be mostly source-and-link compatible with C compilers of the time. Due to this, development tools for the two languages are often integrated into a single product, with the programmer able to specify C or C++ as their source language.

<span class="mw-page-title-main">Python syntax and semantics</span> Set of rules defining correctly structured programs

The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted. The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages. It supports multiple programming paradigms, including structured, object-oriented programming, and functional programming, and boasts a dynamic type system and automatic memory management.

A property, in some object-oriented programming languages, is a special sort of class member, intermediate in functionality between a field and a method. The syntax for reading and writing of properties is like for fields, but property reads and writes are (usually) translated to 'getter' and 'setter' method calls. The field-like syntax is easier to read and write than many method calls, yet the interposition of method calls "under the hood" allows for data validation, active updating, or implementation of what may be called "read-only fields".

In computer programming, an anonymous function is a function definition that is not bound to an identifier. Anonymous functions are often arguments being passed to higher-order functions or used for constructing the result of a higher-order function that needs to return a function. If the function is only used once, or a limited number of times, an anonymous function may be syntactically lighter than using a named function. Anonymous functions are ubiquitous in functional programming languages and other languages with first-class functions, where they fulfil the same role for the function type as literals do for other data types.

This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.

Different command-line argument parsing methods are used by different programming languages to parse command-line arguments.

Nemerle is a general-purpose, high-level, statically typed programming language designed for platforms using the Common Language Infrastructure (.NET/Mono). It offers functional, object-oriented, aspect-oriented, reflective and imperative features. It has a simple C#-like syntax and a powerful metaprogramming system.

In programming languages, name resolution is the resolution of the tokens within program expressions to the intended program components.

References

  1. 1 2 3 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. 1 2 メタ構文変数 (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.