A small, executable course about quines, self-reference, and the moment code begins to talk about itself.
A quine is a program whose only output is its own source code. It does not open its file. It does not receive a copy of itself as input. Somehow, the program already contains everything it needs.
That sounds like a trick. It is a trick—but it is also a clean doorway into quotation, fixed points, compilers, and a deep idea that appears all over computer science: making a thing refer to its own description.
This course takes about an hour. You need Python 3, a text editor, and a little curiosity. No packages, build system, or prior theory are required.
The commands below use python3, as on macOS and Linux. In Windows PowerShell,
use the Python launcher py instead.
If you are reading on GitHub, you can use Code → Download ZIP. Or clone the repository:
git clone https://github.com/oddurs/a-program-looking-in-the-mirror.git
cd a-program-looking-in-the-mirrorThen meet the specimen before anyone explains it:
python3 lab/first_quine.pyNow open COURSE.md. There is also a printable, single-page edition that works offline, and a hosted reading edition.
COURSE.md the complete guided journey
lab/first_quine.py the first surprising specimen
lab/unfinished_quine.py a workbench for building your own
lab/broken_quines/ four small failures to diagnose
gallery/ the same idea in JavaScript and C
tools/verify.py an exact, byte-for-byte quine checker
answers/ hints and explanations for the exercises
To ask the machine whether the Python specimen is really a quine (and stop it after five seconds if an experiment loops forever):
python3 tools/verify.py lab/first_quine.pyIf you also have Node.js and a C compiler, verify the whole gallery:
make checkmake is only a convenience. On Windows, the equivalent checks are:
py -m unittest discover -s tests -v
py tools/verify.py lab/first_quine.py gallery/javascript.js gallery/c.cThe course starts with the phenomenon, then earns the explanation one piece at a time. Every odd character is made to account for itself. Short experiments come before terminology; the theory arrives only after the mechanism feels ordinary.
If you teach from this repository, resist the urge to reveal the finished quine too quickly. The useful part is not seeing one. It is discovering why one must be possible.
The writing and code are available under the MIT License. Share the course, adapt it, and make something strange.
