The programs that print their own source code
In computer science, a "quine" is a program that takes no input and outputs an exact copy of its own source code. Named after logician Willard Van Orman Quine, writing one is a classic programming challenge. It cannot cheat by simply reading its own file from the disk. Instead, the code must contain a self-referential trick, typically utilizing a template string that formats itself with its own contents.
The Paradox of Self-Printing Code
At first glance, writing a program that outputs its own exact source code appears to create an impossible infinite regress. If a developer instructs a program to print a specific line of code, that print command itself is part of the source code and must also be printed. Including a second print command to display the first command merely shifts the problem, because the second print command must now be printed as well. This naive approach leads to an endless expansion where the program always needs more code than it can describe.
In computer science, a program that resolves this paradox without taking any external input is known as a quine. A genuine quine must produce its complete, character-for-character source code purely through internal computation. It cannot read its own file from a hard drive, query an operating system for its source path, or read from standard input. Overcoming this restriction requires an algorithmic method of self-reference, forcing programmers to rethink how data and executable instructions interact.
Philosophical Roots and Naming
The term was introduced by Douglas Hofstadter in his 1979 book, Gödel, Escher, Bach: An Eternal Golden Braid. Hofstadter coined the name in honor of the American logician and philosopher Willard Van Orman Quine, who studied indirect self-reference and self-reproducing linguistic structures. Quine examined paradoxes generated when statements refer to their own construction without directly using self-referential pronouns like 'I'.
A classic example from Quine's linguistic work is the sentence: 'Yields falsehood when preceded by its quotation' yields falsehood when preceded by its quotation. By taking an unquoted descriptive phrase and appending it to a quoted version of that exact same phrase, the sentence constructs a complete statement about itself. Computational quines operate on precisely this structural principle, translating philosophical logic into concrete syntax.