Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
1  
There isn't a practical application that I know of. –  Robert Harvey Sep 28 '11 at 17:07

4 Answers 4

up vote 5 down vote accepted

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 if (login == "Trojan") login(); (more probably written in proper C), but something like that would be too obvious in the code. So what he did was to embed it in a quine and hide it in the binaries of the C compiler.

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.

share|improve this answer
1  
That's my understanding too. The only practical use of a quine is in malware. –  JohnFx Sep 28 '11 at 18:38

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.

share|improve this answer

I've used Quine-like techniques in web pages in the past. Mind you, this was in 1998-99...

I had what we now call a "web app", a set of CGI-BIN programs, some of which performed some time-consuming interactions with mainframes. In order to save doing the time-consuming part twice, in certain cases I would send along JavaScript that could re-write the original page into a form to send back pre-computed information to "reserve a spot in the future". I can't recall what peculiarity of JavaScript interpretation at the time required it, but Quine-like encoding, and decoding on output, of the "reserve a spot in the future" HTML and associated JavaScript became necessary.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.