Quines, which are programs that generate their own code as part or all of their output are a neat idea for a programming puzzle. However, do they have any use beyond that?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
The only time I ever heard of any practical use for quines is when Ken Thompson used it to hide a Trojan horse in the Unix login program.
The Trojan consisted of something like
The quine's self replicating properties were enough to ensure that even though there was no trace of this backdoor in any source code, it would effectively compile every time a C compiler would come across a Unix login() function.
I guess clearer explications could come from reading the paper. It's a good paper.
After some Googling, the surprising answer is that there is at least some theoretical academic effort to use them to make code self repairing, apparently.
One of my search terms was "genetic programming", if anyone wants to look further - it's the only potentially useful related programming area I could think of.
EDIT - Just found the use of Quines in an English outline of a Mathematical proof (Ron Maimon's answer) of Godel's Theorem.
A quine was used to seed Tierra, a digital organism simulator, and life then evolved from it. The quine was used because it guaranteed that the first generation would produce viable offspring.
The evolution led to many interesting results, including parasitic and symbiotic life forms, and even meta-parasites. Might that be considered 'useful'?
I've used Quine-like techniques in web pages in the past. Mind you, this was in 1998-99...