“Talk about software development is dominated by practical considerations,” developer/podcaster Adam Gordon Bell told me Friday in an email. But programming is also an act of creativity, and there’s also a real value in the way that programmers play.
— Blackle Mori (@suricrasia) April 10, 2021
New Podcast Episode. Some highlights:
→ How to write self-reproducing code
→ The history of printers catching on fire
→ How not to fix a bug
→ Why you really can’t trust your compiler
Also, @Donald_McKay asks me about Wing Commander and if I’ll take my Xmas lights down.
— Adam Gordon Bell 🤓 (@adamgordonbell) September 2, 2021
And among its hilarious bits of lore, the collection had included the mind-boggling programming phenomenon known as quines. Quite simply, a quine is a program whose output is … the complete text of the program.
But this soon led to a cultural observation. After hearing how baffling this might be — and providing the trick for creating them — Bell had received a reasonable question from the podcast’s guest, Donald McKay, an Ontario-based senior full-stack developer at an e-learning platform named B Online Learning Limited.
McKay’s question: Why? “Is it a mental exercise? What’s the practical use of a quine?”
Why indeed. It’s a question that developers around the world have attempted to answer. But beyond the powerful but obscure applications of quine-like programming structures, maybe there’s also lurking some fundamental human impulse embedded in the culture of programmers today.
To explore, to strive — and to play.
“One way to think of it is just as a puzzle,” Bell began his podcast episode on quines. “How can you do this?”
“I like quines because they are just fun little riddles,” Bell explained in Friday’s email. “They aren’t anything practical and that is the point.”
After the podcast aired, Bell found that a lot of listeners agreed. While software development discussions can be dominated by practical considerations, “many got into tech because they liked to build fun things with computers, and quines can be a reminder to do something fun and useless once in a while.”
A fun thread on quines from a former creator! https://t.co/zN9NEw2xab
— Adam Gordon Bell 🤓 (@adamgordonbell) September 11, 2021
Before the podcast ended, Bell was even discussing so-called “radiation-hardened” quines. Since it’s theoretically possible that a solar flare could change a bit on your hard drive, there’s actually a genre of quines that, as Bell described it, “encode themselves more than once, so that they can error correct on their output.”
But, he warned the audience, “it gets more complicated.”
128 Quines in One
Wikipedia’s quine page also pointed out the related concept of quine-relays — in which a program in one language outputs a program in another language which … outputs the original program (in the first language).
“Once again, it doesn’t seem like something that should be possible,” Bell marveled on the podcast, “but it just uses the same trick.”
And this leads to the greatest quine of all time, safely ensconced in the GitHub repository of Yusuke Endoh, a developer who proudly identifies themself as the world’s No. 1 player of the International Obfuscated C Code Contest. (This claim could not be officially verified, but Endoh has submitted winning entries in at least 13 different years.)
Endoh’s repository boasts a Ruby program that generates a Rust program that generates a Scala program that generates … on and on, through 128 different programming languages in total.
The 128th iteration is a program written in IBM’s 42-year-old programming language Rexx, which generates the original Ruby program to again iteratively generate the same cycle of quines again in those 128 different programming languages. (Though the repository’s ReadMe file warns that you’ll need to install all the compilers and interpreters for those 128 languages…) There’s even a daunting list of the 128 different shell commands needed to run each of the various programs.
And of course, the ReadMe file also includes instructions for building and running the image in a Docker container.
17 contributors helped assemble the monstrous program.
The comments in the source code provide some useful background information — while showing off the developer’s sense of humor. “Good news: I published a book, [“The World of Obfuscated, Esoteric, Artistic Programming”] It explains how to write a quine, an ASCII-art quine, and a uroboros quine like this quine-relay… Bad news: It is written in Japanese. I hope you could translate it to English and help me earn royalties.”
Back on the podcast, Bell told his audience “I didn’t even know there were 128 programming languages. That’s a lot.” But towards the end of his show, he expressed his admiration for the sheer joy it seems to reveal. Endoh, Bell said, is “doing it for some weird aesthetic kicks or something … Nobody is paying him.”
And there was a spontaneous outpouring of appreciation tucked away on the project’s GitHub repository. The bottom of the ReadMe page closes with a frequently-asked-questions section — where the first question is simply, “Why?”
It links to the “Issues” page of the repository, where a developer named “gonzohunter” had asked that question back in 2013.
Endoh had replied with a simple two-word response — “Why not?”
But the question kicked off an international outpouring of pure support — over 50 responses and counting — from programmers all around the world. In an impromptu parade of pride, it became almost a celebration of the culture from which they came, as each one tried to answer the question in their own words.
From Italy, developer Maurizio De Santis posted, “Because it’s beautiful and funny. It’s ‘nerd art.'”
In Argentina, Jonathan-R0 posted, “To be the first.”
From Austria, developer “seclorum” posted, “it is immediately satisfying to gaze into one’s navel and see the entire universe.”
Developer José Morais repurposed John F. Kennedy’s rationale for why we chose to go to the moon. “Not because it is easy, but because it is hard.”
A developer named Xusheng Li posted “Because the essence of programming is repeating.”
Theophanes Raptis posted from Athens, “For the hell of it of course!”
From Nigeria, developer Gbenga Oladipupo posted “This is the craziest issue I have ever found on GitHub. I love it.”
My favorite response came from Florida-based developer Dustin Oprea. His own GitHub profile begins with the quote, “Show me a problem I can’t seem to solve, and I’ll show you an annoyed family and a wasted family vacation.” But to the question of why, Oprea provided an answer that was both inspiring and thoughtful.
Besides the challenge, he wrote, “often times, the journey produces lessons along the way that can be applied to other problems. On occasion, it’s a trainwreck that produces little fruit. However, when the answer is found, you might find new ways to do old things.
“If the answer is elegant, you can put another star next to your name attesting to the fact that there is one more question that you’ve never backed down from, and answered beautifully.”
Polyglots, Portables and Trust
Where does it all lead? Later in the podcast Bell talked about polyglot code — a single piece of code that can be run in more than one language (sometimes producing different results). This gets especially interesting when you consider the whitespace programming language, in which only various forms of whitespace are considered to be input.
But Bell even found an online thread where programmers kept trying to add additional languages to a polyglot piece of code —where each subsequent iteration incremented the value of the output by exactly one. How many programming languages were they up to now? Bell reported, “The thing that I found said that they had 101.”
And meanwhile, he pointed out, developer Justine Tunney has accomplished a similar trick with compiled executable files. Tunney’s LinkedIn profile shows a six-year stint at Google as a software engineer and site reliability engineer (as well as work on a variety of projects including TensorFlow).
As Tunney explained at Justine.lol, “One day, while studying old code, I found out that it’s possible to encode Windows Portable Executable files as a UNIX Sixth Edition shell script … Once I realized it’s possible to create a synthesis of the binary formats being used by Unix, Windows, and MacOS, I couldn’t resist the temptation of making it a reality, since it means that high-performance native code can be almost as pain-free as web apps.”
Quine-like exercises go back a long time. Back in 1984, while accepting a Turing Award, Unix pioneer Ken Thompson recalled that “In college, before video games, we would amuse ourselves by posing programming exercises. One of the favorites was to write the short self-reproducing program.
“Since this is an exercise divorced from reality, the usual vehicle was FORTRAN.”
Later in his 2021 podcast, Bell noted the real point of that lecture: that there are compilers that generate compilers, in an almost quine-like pattern. Thompson titled his lecture “Reflections on Trusting Trust,” pointing out — purely hypothetically — that this ultimately means that it’s also possible to hide an undetectable superuser password-generating snippet into the binary code of the compilers that will ultimately compile operating system code.
Keep Programming Weird
But later on in the podcast, Bell seemed to hit on the true significance of quines.
“They make me think back to this time of just building fun things … So much of stuff about computer programming is like, what’s the best way to scale some giant service, or what’s the best way to represent business requirements? Or how do we be truly Agile?
“I just want to do the coolest stuff … I don’t know what the practicality of any of this is, but it’s beautiful in a weird way.”
Bell ends his podcast with this advice to his audience. “So if you’re listening: build weird things.”
- How the countries of the world are tempting digital nomads.
- Researchers suggest remote working at Microsoft reduced collaboration and communication.
- 71-year-old Steve Wozniak’s new startup sets its sights on outer space.
The New Stack is a wholly owned subsidiary of Insight Partners, an investor in the following companies mentioned in this article: Docker.