Fact-checked by Grok 2 weeks ago

Metasyntactic variable

A metasyntactic variable is a placeholder identifier used in , , and examples to represent an arbitrary or unspecified , such as a , , or value, without implying any specific meaning or content. These variables facilitate discussions about code structure, algorithms, or language features by abstracting away concrete details, allowing programmers to focus on general patterns and logic. Originating in early and academic culture, they are intentionally nonsensical to avoid confusion with real-world terms. The most widely recognized sequence of metasyntactic variables in English-speaking programming communities is foo, bar, baz, often extended to quux or qux. These terms are not assigned permanent roles in production code; instead, they appear in tutorials, , and temporary files that can be discarded. Variations exist by region or institution—for instance, programmers may use toto, titi, tata, and tutu, while enthusiasts favor spam and eggs inspired by a sketch. Such conventions promote clarity in collaborative environments, as they signal intentional placeholders rather than errors or specific identifiers. The origins of these variables trace back to mid-20th-century computing and military slang. Foo first appeared in pre-World War II American comic strips like Smokey Stover (1930s), where it was a humorous nonsense word, and gained traction in WWII military jargon through terms like "foo fighters" (unidentified aerial phenomena) and the acronym FUBAR ("Fucked Up Beyond All Recognition"). By the 1950s and 1960s, foo and bar entered hacker lexicon at institutions like MIT's Tech Model Railroad Club (TMRC), where they served as metasyntactic stand-ins in technical discussions and early programming examples. Baz followed as the third in the sequence, solidifying the trio's use in documentation by the 1970s, as evidenced in over 200 Internet Engineering Task Force (IETF) Request for Comments (RFCs) documents since 1971. In broader context, metasyntactic variables reflect the hierarchical nature of programming languages, enabling meta-abstraction that mirrors how higher-level languages build upon lower ones. They embody a of , fostering a shared among developers worldwide while underscoring the playful yet precise ethos of . Their persistence in modern resources, from textbooks to online forums, highlights their role in making complex concepts accessible without introducing unintended semantics.

Definition and Purpose

Definition

A metasyntactic variable is a employed in technical examples and discussions within , particularly programming, to represent an arbitrary or unspecified entity such as a , , or value, without connoting any particular identity or meaning. These variables serve to illustrate or conceptual points, emphasizing form over content, and are chosen for their neutrality and recognizability as stand-ins. Common illustrations include "foo" and "bar," which are frequently substituted in place of actual identifiers to avoid distraction from the example's intent. The prefix "meta" in "metasyntactic variable" denotes a level of in the used to describe programs or constructs, where such variables for other variables or elements rather than holding values themselves. This usage aligns with broader linguistic and logical conventions, but in contexts, it specifically highlights placeholders that facilitate meta-level discourse about without binding to specific semantics. Metasyntactic variables differ from syntactic variables in theory, where the latter refer to nonterminal symbols in a —abstract placeholders that are systematically replaced by productions to generate strings in the object , as defined in standard notations like G = (V, Σ, P, S), with V as the set of nonterminals. Similarly, they are distinct from metavariables in logic, which are symbols in a that represent arbitrary expressions or terms from an object , often used in proofs or semantic analyses to denote unspecified syntactic elements without the informal, example-oriented connotation of metasyntactic variables. This distinction underscores the practical, illustrative role of metasyntactic variables in programming versus the formal, theoretical roles in and logic.

Purpose

Metasyntactic variables primarily serve as placeholders in technical documentation, tutorials, and discussions to specific details, enabling a focus on the underlying structure, syntax, and logic rather than concrete content or real-world identifiers. This avoids introducing naming conflicts or assumptions about particular implementations, allowing examples to remain general and applicable across diverse scenarios. In programming and computing contexts, they promote universality by using neutral terms that do not imply domain-specific meanings, thus facilitating clearer communication of algorithms, function behaviors, and standards without bias toward any single application. For instance, in describing function arguments or file operations, metasyntactic variables highlight the procedural flow, making it easier for readers to recognize patterns and apply concepts independently. The benefits of this approach include enhanced readability and accessibility in educational materials, as the placeholders reduce by emphasizing form over substance, which aids in teaching and demonstrating algorithmic principles. Additionally, they support consistent practices, ensuring portability and minimizing confusion in collaborative or international settings where real names might carry unintended connotations.

History

Origins

The term "foo" traces its etymological roots to pre-computing culture in the 1930s and 1940s, originating as a nonsense word in the U.S. comic strip Smokey Stover by Bill Holman, where it appeared frequently on license plates and in playful phrases such as "He who foos last foos best." It also featured in Warner Brothers cartoons, including a 1938 short where displays a sign reading "SILENCE IS FOO!," further embedding it in popular slang. Additionally, "foo" may derive from the Chinese character "fu" (meaning happiness or good fortune), which Holman reportedly encountered on a figurine and incorporated into his work. During , the term gained military associations through "foo fighters," unexplained aerial phenomena observed by pilots, potentially linking it to broader wartime . The companion term "bar" entered technical parlance via World War II U.S. military slang, particularly the acronym FUBAR ("Fucked Up Beyond All Recognition" or "Fouled Up Beyond All Repair"), which described hopelessly confused situations and proliferated among soldiers in the 1940s. This acronym, part of a family of backronyms like SNAFU ("Situation Normal: All Fucked Up"), transitioned into postwar hacker lore through veterans who influenced early computing communities, where "foo" and "bar" began pairing as neutral placeholders. The combination "foobar" likely solidified in this context, evoking the irreverent humor of military acronyms without direct derivation from FUBAR itself. The first documented uses of "foo" in a computing context appear in 1959, within the "Dictionary of the TMRC Language" compiled by the Tech Model Railroad Club (TMRC) at , defining it as "the sacred syllable (FOO MANI PADME HUM)," a humorous nod to Buddhist chant adapted for . This MIT group, a hotbed of early , helped propagate the term through technical memos and model railroad simulations that prefigured programming practices. By the early 1960s, "foo" and "bar" surfaced in ARPA-funded reports and MIT documentation, marking their adoption as metasyntactic variables for illustrating code structures without semantic distraction.

Evolution in Computing

During the 1960s and 1970s, metasyntactic variables gained traction within computing culture, particularly among hackers at MIT's and Project MAC, as well as at Stanford, where they served as placeholders in early programming manuals, code discussions, and system documentation. These nonsense words, such as "foo" and "bar," facilitated abstract explanations of syntax and logic without tying examples to specific contexts, reflecting the informal, inventive spirit of nascent communities. The practice was captured in the inaugural compilation of the in 1975 at MIT-AI, which listed "foo" as the primary metasyntactic variable in syntax examples and noted its propagation through DEC system manuals. A pivotal milestone in their adoption occurred in 1978 with the publication of by Brian W. Kernighan and Dennis M. Ritchie, which incorporated "foo" and "bar" in illustrative code snippets, embedding these variables into mainstream programming pedagogy and broadening their use beyond elite hacker circles. Concurrently, their presence in (IETF) (RFCs) began early, with the first instances in RFC 269 from December 1971, establishing a pattern of standardized placeholder usage in technical specifications. By the late , the term "metasyntactic variable" itself emerged in computing literature, with one of its earliest known uses in the 1979 MDL Primer by Gregory C. Steele, to describe these placeholders formally. In the 1980s and 1990s, metasyntactic variables proliferated through newsgroups, where the circulated widely among programmers, and in programming textbooks that routinely employed them for clarity in syntax demonstrations. This era saw their integration into diverse computing subcultures, reinforced by ongoing usage—reaching dozens of documents by the 1990s—and their role in lore, as chronicled in published editions of the starting in 1983. From the 2000s to the present, these variables have endured in open-source project documentation, specifications, and online tutorials, influenced by dissemination of code and standards, with English-origin terms like "foo" and "bar" retaining dominance amid , as evidenced by their continued appearance in over 200 by 2001 and beyond.

Common Metasyntactic Variables

English-Language Variables

In English-language programming contexts, the canonical sequence of metasyntactic variables is foo, bar, baz, qux, quux, corge, grault, garply, , , plugh, , . This ordered list serves as a standardized progression for placeholders in examples, allowing programmers to denote multiple entities without implying specific meanings. These variables follow established conventions rooted in , where foo and bar are typically paired for simple contrasts, such as distinguishing two functions or parameters. For more intricate illustrations involving several components, the sequence extends progressively (e.g., foo, bar, baz for three items). Programmers select these nonsense words deliberately to avoid meaningful terms that could confuse readers or imply unintended semantics, ensuring clarity in abstract demonstrations. Notably, draws from the 1976 text adventure game , where it functions as a magic command, embedding gaming lore into technical examples. A common variation in Python-influenced contexts includes , eggs, and ham, inspired by the comedy sketch "Spam," reflecting the language's humorous naming ethos while primarily suiting data or list examples. These terms maintain the core purpose of neutrality but adapt to cultural preferences within specific communities.

Non-English Variations

In non-English programming and documentation contexts, metasyntactic variables often adapt to local linguistic and cultural norms, serving as placeholders that resonate with native speakers while sometimes retaining English-origin terms like foo and bar for international compatibility. This blend facilitates accessibility in localized technical writing, where nonsense words or culturally familiar terms replace or supplement global standards to enhance readability without altering core concepts. In Japanese technical documentation and code examples, common metasyntactic variables include hoge (equivalent to foo), fuga (equivalent to bar), and piyo (equivalent to baz), often derived from onomatopoeic sounds or playful expressions influenced by manga and everyday language. These terms appear frequently in local tutorials and API references, with variants like hogehoge used for emphasis or repetition, reflecting a preference for rhythmic, non-semantic placeholders that align with Japanese phonetic patterns. French-speaking programmers typically employ toto, titi, tata, and tutu as a standard sequence of metasyntactic variables, drawing from repetitive, childlike syllables common in francophone language and . These are used in examples within French-language resources, such as educational materials and code snippets, with blabla occasionally serving as a casual filler for generic or verbose placeholders akin to "blah blah" in English. In Italian contexts, metasyntactic variables often reference characters, with pippo (), pluto (), and paperino () forming a popular sequence in tutorials and . This cultural leverages familiar pop icons to make abstract examples more relatable, appearing in Italian-specific programming guides and online resources. Across these and other non-English environments, English terms like foo and bar persist in multinational projects and open-source codebases, but native adaptations prevail in region-specific to promote linguistic inclusivity and reduce for local developers.

Usage in Programming Languages

C and C++

In C and C++, metasyntactic variables such as foo, bar, baz, and qux serve as placeholders in code examples to focus on syntax and mechanics rather than domain-specific semantics. A common C example illustrates procedural function definition and parameter passing with foo and bar:
c
#include <stdio.h>

int add(int foo, int bar) {
    return foo + bar;
}

int main() {
    int result = add(3, 4);
    [printf](/page/Printf)("Result: %d\n", result);
    return 0;
}
This demonstrates basic arithmetic operations without implying real-world variable meanings. To highlight pointer usage and explicit memory management in C, consider a swap function:
c
#include <stdio.h>

void swap(int *foo, int *bar) {
    int temp = *foo;
    *foo = *bar;
    *bar = temp;
}

int main() {
    int a = 3, b = 4;
    printf("Before: a=%d, b=%d\n", a, b);
    swap(&a, &b);
    printf("After: a=%d, b=%d\n", a, b);
    return 0;
}
Here, pointers allow the function to modify external variables, underscoring C's low-level control over . In C++, these variables extend to object-oriented features like es and methods. For instance, a definition might use baz and qux to exemplify encapsulation:
cpp
#include <iostream>

[class](/page/Class) Example {
private:
    int baz;
public:
    void set(int qux) {
        baz = qux;
    }
    int get() const {
        return baz;
    }
};

int main() {
    Example obj;
    obj.set(42);
    std::cout << "Value: " << obj.get() << std::endl;
    return 0;
}
This shows member variables, access specifiers, and method implementation, focusing on OOP principles without semantic distraction. C emphasizes procedural paradigms with direct memory handling via pointers, whereas C++ builds on this by introducing OOP extensions like classes for data abstraction and inheritance.

Python

In Python, metasyntactic variables serve as placeholders in code examples to illustrate concepts without implying specific semantics, aligning with the language's emphasis on readability and Pythonic idioms such as clear, descriptive naming conventions. Unlike more traditional options like foo and bar, Python documentation and tutorials frequently employ spam, eggs, and ham, drawing from the Monty Python's Flying Circus sketch that inspired the language's name. This choice reflects the community's humorous bent and promotes memorable, contextually neutral examples in scripting and data processing tasks. A common illustration appears in list comprehensions, where foo and bar might represent iterable elements for demonstrating transformations:
python
foo = 3
bar = 5
result = [x * 2 for x in [foo, bar]]  # Outputs: [6, 10]
Such usage highlights Python's concise syntax for data manipulation, though spam and eggs could substitute for a more idiomatic flavor. In data-oriented functions, , ham, and eggs often stand in for inputs in simple processing routines, emphasizing the language's suitability for quick prototyping:
python
def process(spam, eggs):
    return spam + eggs  # Placeholder for aggregating data values

result = process(10, 20)  # Example output: 30
This convention underscores Python's focus on straightforward, readable code, where these variables evoke everyday computations without distracting from the logic. Python's dynamic further enhances the flexibility of metasyntactic variables, enabling seamless reassignment of types in interactive REPL sessions or scripts— for instance, treating eggs as an in one line and a in the next— which supports rapid experimentation and placeholder-driven teaching.

Other Languages

In , metasyntactic variables such as foo and are frequently employed in illustrative code snippets, particularly for demonstrating structures and variable declarations. For instance, the official Java code conventions document uses foo in examples like int foo, fooarray[]; to highlight naming and formatting guidelines, though it notes this as an incorrect style for mixing types on one line. Similarly, placeholder classes might appear as public [class](/page/Class) Foo { [private](/page/Private) [Bar](/page/Bar) bar; } to exemplify object-oriented concepts without specifying domain-specific names. In and , metasyntactic variables often take the form of single letters like x, y, and z in functional expressions, reflecting the languages' emphasis on mathematical and symbolic notation. The Revised^5 Report on Scheme (R5RS), a foundational standard, routinely employs these in binding constructs, such as (let ((x 2)) (+ x 3)) to illustrate lexical scoping and . The sequence extends to terms like quux in broader Lisp documentation and examples, aligning with established conventions from traditions where originated. JavaScript documentation and examples similarly favor foo and bar for placeholders in modern syntax like arrow functions and objects. The Mozilla Developer Network (MDN) Web Docs, an authoritative reference, demonstrates dynamic typing with code such as let foo = 42; foo = "bar";, showing how variables can change types to clarify JavaScript's loose typing behavior. Across these and other languages, English-derived terms like foo and bar predominate as metasyntactic variables, even in syntax influenced by non-English origins, due to the historical Anglo-American roots of culture. Local adaptations remain rare; for example, adheres to English standards, using foo and bar in its core documentation and community examples without significant localization, reinforcing global consistency in placeholder usage.

Usage in Documentation and Standards

IETF Requests for Comments

Metasyntactic variables have played a significant role in IETF Requests for Comments (RFCs) since the inception of the series in 1969, serving as placeholders to illustrate behaviors without referencing specific implementations. In the inaugural RFC 1, "Host Software," the generic term "HOST x" denotes an arbitrary host in descriptions of establishment and data transmission processes, such as "Initiate TTY-like with HOST x." These early placeholders established a convention for abstract representation in network specifications. The adoption of "foo" and "bar" as metasyntactic variables emerged in subsequent RFCs, with the first documented use in RFC 269, "Some Experience with File Transfer," from 1971, where "FOO" exemplifies a filename in commands such as "DF FOO" for deletion and "PF FOO" for sending. By 2001, RFC 3092, "Etymology of 'Foo'," reports that approximately 212 RFCs, beginning with RFC 269, employed "foo," "bar," or "foobar" as metasyntactic variables, typically for sample names of programs, files, or network components. Usage has continued to grow since then, with the terms appearing in hundreds of subsequent RFCs as of 2025. Later documents such as RFC 793, "Transmission Control Protocol," use labels like "TCP A" and "TCP B" for generic entities in connection diagrams. The primary purpose of these variables in RFCs is to represent generic hosts, packets, or fields in a manner, eschewing vendor-specific or real-world names to maintain and focus on conceptual clarity. For instance, in examples, "foo.bar.com" often serves as a placeholder domain in address mappings and message flows, as seen in specifications. Similarly, in DNS-related RFCs, constructs like "CNAME foo.bar.example.net" illustrate redirection without implying actual infrastructure. This practice evolved from the ARPANET-era memos that formed the early RFCs, persisting into contemporary standards. Even in modern documents like RFC 6593, "Service Undiscovery Using Hide-and-Go-Seek," "foo," "bar," and "foobar" denote metasyntactic service names in protocol hiding techniques, upholding the tradition for illustrative purposes in IPv6-era specifications.

SQL Examples

In database management system (DBMS) documentation, such as that for and , metasyntactic variables like foo, bar, and baz serve as placeholders for names, column names, and values in SQL examples, allowing generic illustration of syntax and operations without implying specific real-world . This practice is prevalent in official tutorials to demonstrate concepts like creation, insertion, querying, and schema testing in a neutral manner. Table creation examples often employ these variables for column names or source tables. For instance, MySQL documentation illustrates populating a new table from an existing one using:
sql
CREATE TABLE bar (m INT) SELECT n FROM foo;
Here, foo and bar represent arbitrary tables, with the statement inserting rows from foo into bar while applying defaults to any new columns. Similarly, PostgreSQL examples define a table as:
sql
CREATE TABLE people (
    id bigint GENERATED ALWAYS AS IDENTITY,
    name text,
    address text
);
followed by:
sql
INSERT INTO people (name, address) VALUES ('A', 'foo'), ('B', 'bar');
This setup tests basic schema definition and insertion without domain-specific content. Queries using metasyntactic variables commonly demonstrate filtering, joins, and aggregations. In PostgreSQL's table expressions documentation, a lateral join is shown as:
sql
SELECT * FROM foo, LATERAL (SELECT * FROM bar WHERE bar.id = foo.bar_id) ss;
where foo and bar stand in for related tables to highlight subquery integration. For pattern matching, MySQL provides:
sql
SELECT COUNT(*) FROM foo WHERE bar LIKE '%baz%';
This counts rows in table foo where column bar matches the pattern containing baz, exemplifying the LIKE operator for string searches. Another PostgreSQL query example concatenates strings:
sql
SELECT 'foo' 'bar';
which equates to SELECT 'foobar';, clarifying lexical rules for adjacent string literals. Sample data rows in these documents use foo, bar, and baz as placeholder values to populate tables for schema validation or query testing. PostgreSQL's identity columns section includes the insert example above, generating auto-incremented IDs alongside these neutral entries to showcase sequence behavior. MySQL similarly inserts mixed null and placeholder values:
sql
INSERT INTO foo VALUES (NULL), (NULL);
followed by a query like SELECT COUNT(*) FROM foo WHERE bar NOT LIKE '%baz%' OR bar IS NULL;, to explore null handling and pattern exclusion in generic datasets. Such representations ensure examples remain abstract and reusable across DBMS tutorials.

References

  1. [1]
    metasyntactic variable
    ### Summary of Metasyntactic Variable
  2. [2]
  3. [3]
    RFC 3092 Etymology of "Foo" - IETF
    1. The second metasyntactic variable, after foo and before baz. "Suppose we have two functions: FOO and BAR. FOO calls BAR...." ...
  4. [4]
    The Jargon File Glossary - metasyntactic variable - ZVON.org
    A name used in examples and understood to stand for whatever thing is under discussion, or any random member of a class of things under discussion.Missing: definition | Show results with:definition
  5. [5]
    Meta-variable - Glottopedia
    Oct 15, 2007 · A meta-variable is an expression of a metalanguage that can be used to refer to arbitrary object language expressions in a logical language.
  6. [6]
    @var (GNU Texinfo 7.2)
    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 @ ...<|separator|>
  7. [7]
    Historical questions on the term "general abstract nonsense"
    Oct 29, 2012 · The term general abstract nonsense is believed to have been coined by Norman Steenrod - and surely it was not intended by him as a putdown.
  8. [8]
  9. [9]
    foobar
    ### Summary of Etymology and Origins of 'foobar', 'foo', and 'bar'
  10. [10]
    foo - catb. Org
    When 'foo' is used in connection with 'bar' it has generally traced to the ... Early versions of the Jargon File interpreted this change as a post-war ...
  11. [11]
    metasyntactic variable
    ### Summary of Metasyntactic Variables
  12. [12]
    "Adventure," or "Colossal Cave Adventure," is the First Computer ...
    "Adventure," or "Colossal Cave Adventure," was the first computer text adventure game, created by William Crowther in 1975-76, based on Mammoth Cave.
  13. [13]
    metasyntactic variable - catb. Org
    metasyntactic variable ; foo, bar, bletch: Waterloo University. We are informed that the CS club at Waterloo formerly had a sign on its door reading “Ye Olde Foo ...
  14. [14]
    Metasyntactic variables: do you use something else than "foo", "bar ...
    Aug 6, 2009 · Metasyntactic variables: do you use something else than "foo", "bar" according to your mother tongue. Usually, I often use titi , toto and huhu ...Missing: textbooks 1980s 1990s
  15. [15]
    Metasyntactic Variable - Glossary - DevX
    Aug 23, 2023 · For example, in French, commonly used Metasyntactic Variables are 'toto', 'titi', 'tata', 'tutu'.Q: Can I use any name for a Metasyntactic ...<|separator|>
  16. [16]
    Metasyntactic Variable - C2 wiki
    A word, used in conversation or text that is meant as a variable. There is a fairly standard set in the ComputerScience culture. People tend to create their ...
  17. [17]
    2.1 — Introduction to functions - Learn C++
    May 31, 2007 · Other common metasyntactic variables in C++ include “bar”, “baz”, and 3-letter words that end in “oo”, such as “goo”, “moo”, and “boo”). For ...<|control11|><|separator|>
  18. [18]
    Write a function to swap two values using pointers - DaniWeb
    Oct 28, 2009 · void swap(int *num1, int *num2) { int tempvar1; tempvar1 = *num1; *num1 = *num2; /* learn the difference between num1 and *num1 */ *num2 = … — ...
  19. [19]
    C++ Core Guidelines - GitHub Pages
    Jul 8, 2025 · Example. #include <memory> class bar; class foo { public: explicit foo(const std::shared_ptr<bar>& forward_reference) : forward_reference_( ...
  20. [20]
    HowToEditPythonCode - Python Wiki
    Sep 17, 2023 · [24][25] For example, the metasyntactic variables often used in Python literature are spam and eggs, instead of the traditional foo and bar.
  21. [21]
    Chapter 4 - Choosing Understandable Names - Invent with Python
    We commonly use a metasyntactic variable in tutorials or code snippets when we need a generic variable name. In Python, we often name variables spam , eggs ...
  22. [22]
    Built-in Types — Python 3.14.0 documentation
    That is, ("spam " "eggs") == "spam eggs" . See String and Bytes literals for more about the various forms of string literal, including supported escape ...
  23. [23]
    None
    ### Extracted Placeholders, Generic Names, and Metasyntactic Variables
  24. [24]
    None
    ### Summary of RFC 269: Some Experience with File Transfer
  25. [25]
    None
    ### Summary of RFC 791: Internet Protocol
  26. [26]
    None
    Summary of each segment:
  27. [27]
    None
    ### Summary of Uses of "foo" and "bar" as Metasyntactic Variables in RFC 6593
  28. [28]
    Documentation: 18: 7.2. Table Expressions - PostgreSQL
    A trivial example of LATERAL is. SELECT * FROM foo, LATERAL (SELECT * FROM bar WHERE bar.id = foo.bar_id) ss;. This is not especially useful since it has ...
  29. [29]
    15.1.20.4 CREATE TABLE ... SELECT Statement
    For each row in table foo , a row is inserted in bar with the values from foo and default values for the new columns. In a table resulting from CREATE TABLE ...
  30. [30]
    Documentation: 18: 4.1. Lexical Structure - PostgreSQL
    For example: SELECT 'foo' 'bar';. is equivalent to: SELECT 'foobar';. but: SELECT 'foo' 'bar';. is not valid syntax. (This slightly bizarre behavior is ...
  31. [31]
    14.8.1 String Comparison Functions and Operators
    ... INSERT INTO foo VALUES (NULL), (NULL);. The query SELECT COUNT(*) FROM ... SELECT COUNT(*) FROM foo WHERE bar NOT LIKE '%baz%' OR bar IS NULL;. STRCMP ...
  32. [32]
    Documentation: 18: 5.3. Identity Columns - PostgreSQL
    INSERT INTO people (name, address) VALUES ('A', 'foo'); INSERT INTO people (name, address) VALUES ('B', 'bar');. would generate values for the id column ...