CoRecursive: Coding Stories - Chat: Quines, Polygot Code, and Other Fun Computations

Episode Date: September 2, 2021

Today, previous guest and my neighbor Don Mckay and I will discuss items from the endless fascinating Cursed Computer Iceberg Meme. The Iceberg is a giant list of "the peculiarities and weirdness of c...omputers." We each a few items from the list and alternate explaining it to each other. Don's choices are varied, and mine focus on quines and esoteric coding problems. We also share some coding horror stories from our past. You can support the podcast and encourage me to keep making it on patreon. Episode Page Subscribe To Podcast Newsletter

Transcript
Discussion (0)
Starting point is 00:00:00 Hello and welcome to Co-Recursive. One piece of feedback I get on the podcast is about an episode I did in the past that was a little bit different called Don and Adam Discuss Folds, where the guest was my neighbor and former colleague Don, and we talked about folds and recursion and stuff. People seemed to really like that episode, so I'm going to do something similar. I haven't quite figured out how to start this episode off, so why don't you state your name and what you do?
Starting point is 00:00:25 My name is Donald McKay, and I'm a senior developer for Beyondline Learning Limited. Despite the fact that we live not that far away from each other, I haven't seen you in some time. No, I haven't seen any other human beings aside from people that work at the grocery store for a very long time. It's just COVID, just sheltered in place and seeing nobody. Yeah, you know, there was one point where I was driving by and I thought to myself, does Adam even still live there? Like maybe you move, maybe you got a different place, right? And I saw the, was it the broken Christmas lights?
Starting point is 00:00:59 And I'm like, yeah, he hasn't taken those down yet. They probably would have taken those down if they sold the house. Yeah, a normal person would have taken those down if they sold the house. Yeah. A normal person would have taken their Christmas lights down by the end of June. So I found this thing online and I sent it to you called the Cursed Computer Iceberg Meme. What did you think of this? There's a lot of weird things to do with computers and programming in general. Yeah, there totally is. So let me describe this to you. So I found it, I think on Hacker News, it's a very large picture
Starting point is 00:01:32 of an iceberg where you can keep scrolling and see more and more of the iceberg. The further down you go, you know, below the water, basically. And there's various levels, like one is called above the water, one is called on the iceberg, one is below the iceberg, and. And there's various levels, like one is called above the water, one is called on the iceberg, one is below the iceberg, and it keeps going down to the deep, to the abyss. And all scattered around the various levels are these terms that link to various articles or Wikipedia pages or tweets about computing. So it could be things like, let me just read some, falsehoods that programmers believe about time. No elegant solution to fizzbuzz exists. Chuck Norris is HTML color, which is super interesting. Parsing Pearl is undecidable. PostScript is Turing complete. And like,
Starting point is 00:02:18 it just keeps on going. The further down you go, you know, the more obscure they are. I think they're trying to say like, oh, you might've heard of, of X like problems with names, but you've probably never heard about Pearl being undecidable. That's like three levels down the iceberg. It's, it's even more obscure. So this could be like a great source of like interesting facts about computers that it could also be like just a great tool for like gatekeeping in the world of computer programming. If you don't know at least one of the things or three of the things from below the waterline, we don't want to talk to you. But I thought it was like there's just so many interesting things in here.
Starting point is 00:02:58 I thought this would be great if you pick some that are interesting and then I pick some that are interesting. We'll just explain them to each other. So that's the idea. Maybe I'll start with one. How does that sound? Yeah. So this one, I think this is near the top of the iceberg so this is a quine have you heard of a quine it's it's q u i n e I have not I saw it on the list but I have not heard of it nice okay so that's perfect so a quine is a program that takes no input at all. And when you run it, it produces itself.
Starting point is 00:03:28 Oh, okay. So that sounds strange, right? So it's like some kind of self-replication thing? Yeah. So it's a self-replicating program. If you were to take it, like you take a Java program and you run it at the command line, what it outputs to the standard out to your console is just like the exact contents of that java program oh all right it sounds super weird right and so it's named after this douglas douglas hofstetter yeah he wrote goodell escher and bach which is which
Starting point is 00:03:59 is a book i read like as a teenager and uh he is very big into i guess like weird types of recursion like it's not a book explicitly about computer programming but it's about a lot of loops and stuff right so like one of the things that was in his book was uh hofstetter's law where he said that a project will always take longer than you think it will even if you you take into account Hofstadter's law. So it's like a recursion. Everything to do with Douglas Hofstadter is like a weird, twisted circle. He has a brand. Yeah.
Starting point is 00:04:35 So Quine is based on, I think it's called Quine's Paradox. And Quine's Paradox, this is going to be super confusing. Quine's Paradox is yields falsehood when preceded by its quotation, yields falsehood when preceded by its quotation.
Starting point is 00:04:52 Which I don't even think you can parse that. But the interesting thing, because I have a couple, there's several on this thing that are related to Quine's. Like the deeper you go down this thing, the more of these quines turn up. How could you even write a program that outputs itself?
Starting point is 00:05:08 Like it's super tricky to think about, right? Like you want to print out a statement that's in your program, but to print out that statement, you need to also have another statement. Yeah, that prints it out, yeah. Yeah, and then for the next, like, you know, to handle printing out the statement
Starting point is 00:05:26 that prints out that statement, you need to have another print statement. And it seems like it should be just an infinitely large program. But there's kind of a trick to it. So imagine that you have a Java program. And then so you say at the top whatever the standard stuff is
Starting point is 00:05:44 of creating a program. So you're like a public static Quine, and then you say public static main. And that's kind of like, you know, the beginning of your program, right? And then, then you have two strings. So you declare like a string, we'll call the first one first, and we'll call the second string second. I'm with you so far. Then you have the bottom of the program, right? So the bottom of the program, the first thing you do is you print out the first string, right? And then the second thing you do is you print out the first string, but you put it into quotes. So you're kind of printing it out as if it's in a string itself. Then the next thing you do is you print out the second string, but you print it out as if it's in quotes. And then the
Starting point is 00:06:31 very last thing you do is you print out the second string itself. So that's kind of the structure of your Quine. And then the question is, what do you put in those two strings, right? So in the first string, you put everything that happened before those strings were declared the top part of your program okay yeah and then in the second string you put everything that happens in the bottom part of your program after your strings are declared and then you've kind of just turned the program inside out on itself so then the program now contains like the the top part of itself and then a string containing the top part of itself, and then a string containing a bunch of print statements, and then the actual print statements.
Starting point is 00:07:08 And then when you run it, obviously it's going to recreate this. So it contains itself twice, once as a string and once as not a string, and then it prints itself twice, but it prints itself twice from the strings. So the contents of the code are actually in the strings? Yeah, so you actually have to write out the code and then also put the code in the strings. So everything's like duplicated. And that way you can print them out.
Starting point is 00:07:34 Is it just like a, is it a mental exercise? Like what is the practical use of a coin? I have some further examples that maybe we'll get to that. But yeah, I mean, one way to think of it is just as a puzzle. So it's like a puzzle, like how can you do this, right? How can you create something that prints itself? And like some people have come up with cheats for it. So like in languages like JavaScript, in JavaScript, you can do eval. So you can take like a string of code
Starting point is 00:08:03 and just like evaluate it. So that makes the problem a lot easier because you don't like any code you can have it as a string but also like run it in the same thing where in java like you kind of have to do it twice there was also somebody i'm just pulling all this from the wikipedia page which is surprisingly fascinating so somebody somebody submitted to a contest, what they called the world's smallest self-producing program, and it was a blank file. And so if you take a blank file and you feed it to the C compiler, it doesn't know what to do with it. So it produces no output, which is also a blank file. But yeah, that's pretty clever. So the, yeah,
Starting point is 00:08:47 the minimal equine is actually nothing. Another thing they were saying is like, if you, if you imagine programs, like in terms of like, like sets, if you have a program that takes in a number and then adds two to it, right? So you run it, you pass it five, it returns seven. So you have that type of program. You can imagine it as like something that like maps a number to that number plus two. So on this side, you have all these numbers and they, you know, you have like one, two, three, and the other of the program, you have like a three, four, et cetera, right? So it's like a maps one number to the next, right? And so a lot of programs can be viewed like this. They take in two numbers, then it's kind of like two arrows go into the program and then
Starting point is 00:09:29 like one number comes out on the other side so if you consider equine in that kind of view it's basically it takes in no input right so it's like a the the arrow part takes in nothing and then what it returns is itself so it's kind of like an arrow that just points around to itself with no input and its only output is itself. That's interesting. It's definitely like one of those kind of like a mental stimulating puzzle,
Starting point is 00:09:57 even trying to figure out how it works. It's kind of like, you know, exercising the logic portions of your brain. Yeah. Trying to figure out. Yeah. Yeah, they had a Java example on the Wikipedia, which is kind of what I'm working off here,
Starting point is 00:10:10 recounting it to you. And it took me a while to read it to kind of understand, like, wait a minute, how does this? And then you're like, okay, yeah, it makes sense. It doesn't do anything besides what it does. Yeah, that's the step, right? When you look at it, your your brain goes that's cool and also what does it do what is the what is the function and i guess the function is it's it's
Starting point is 00:10:32 just a a fun little mental rubik's cube for your coding brain i guess yeah like creating one right and so there's also like an an aspect where like a quine is sort of like a life form, like, you know, like humans, like we reproduce, like we have children, we have our DNA, which is our code, right? And then like that is kind of produces another offspring, right? And if you're like some creatures are like an asexual reproduction, right? And they were kind of a lot like a quine, I guess, right? Like they have code that makes up who they are. And then when they reproduce, they make a new copy of it. So equine is in some sense, something like that, right? It's reproducing itself. It has no other purpose, right? It doesn't actually do anything.
Starting point is 00:11:15 So maybe it's more like a, I don't know, a virus or I don't know, like it reproduces without reason, but it, yeah, like the basic concept is, is true, like for an analogy, but in biological organisms, they reproduce, but they don't reproduce an exact copy. There's always that little bit of evolution built into it, right? So there'll be variations and mutations and the thing that you get, you know, billions of copies down the road is going to be different than the one you started with. It's funny you should mention that, Tom, because this Wikipedia page is deep. That happens through like copying errors, right? Like something tries to reproduce itself and it makes a mistake. And that's kind of evolution is powered by those mistakes. I mean, not all of them are errors, right? Well, aren't they?
Starting point is 00:11:58 No, not all evolution is an error. Evolution is usually a response to stimulus of the environment how better to survive but like at a very low level what happens is a copying error happens right and then if that copying error turns out to be advantageous then it that you know that creature keeps reproducing if it's not advantageous that creature dies yeah yeah so like it all starts out with those errors yeah so we're we're basically exception based logic organisms yeah we just accumulate mistakes and eventually hopefully some of them are good mistakes so what you're saying is human beings are a feature not a bug exactly but so there is a a something called a radiation hardened quine. So the thing is that like the radiation, you know, in theory can like flip bits on your computer, right? Like a solar flare could hit your hard drive and change some single bit. And, you know, if it changed something
Starting point is 00:13:00 where you had written the quine to disk disk it could change like a single character to be slightly different right and in which case that that is like evolution right there's a small copying error that will happen when that runs because of whatever so so somebody created radiation hardened quines which like encode themselves more than once so that they can like error correct on their output so they they, they stopped, they stopped the evolution. I think that we have some redundancies like in our DNA too, because we don't want, like we want to control the amount of,
Starting point is 00:13:32 of like copying errors that happen. You know, we don't want to just fall apart if some single change happens to our DNA. Right. We have some sort of redundancy. Yeah. Anyways, quines,
Starting point is 00:13:43 they're weird. They're weird. Just wait, I got more. So what did you find? So I took LP0 on fire, or otherwise known as printer on fire, error message that's generated in some of the, I guess, I think it's still in the Linux kernel today. I think it is. Back in the late 50s, computers were being used at a lot of laboratories and they needed to print out their calculations. They were using computers for calculations and they needed the results. So they had to print them out and they were spending a lot of their time just waiting around because printers were so slow. So there was a lot of very experimental
Starting point is 00:14:20 units of printers being developed. So I guess they even had one, like a host of printers that used radiation. Like I think they used like a cathode ray tube instead of a laser to essentially be a laser printer. Oh, wow. And yeah, they used the CRT as a light source. But they were experimental and they used heat. A lot of them used heat.
Starting point is 00:14:45 So what could happen is if the printer malfunctioned, the paper could combust. And if it didn't stop, it would just keep jamming paper into the fire. Right? It would just keep feeding the fire more paper. So when I first read that, I was like, oh, that's where it comes from. No, it turns out that these type of printers actually predate that error message. There was no evidence of that message appearing at that time. That was, I guess, a red herring.
Starting point is 00:15:14 Then I started reading about drum printers. Drum printers are high-speed rotary drums. While they're not as dangerous as the previous generation, they could still theoretically catch fire from the friction caused by the drum in the case of severe jams. But no known occurrences of fires have happened from those rotary drums. So maybe that was not the case. So then I started looking at what the actual error was. And I mean like this is all from wikipedia research so there are three states for line printers ready online and check and if
Starting point is 00:15:53 you have online off and check on then that usually means it's out of paper but if you had online on and check on it meant that the printer was still trying to do its job but there was was a problem. And that could theoretically mean that there's a jam, but it's not stopping. The printer is continuing to operate. It's going to shove a bunch of paper in there. And a developer decided that the error message for that should be the printer is on fire. Oh, so it wasn't even based around a real fire?
Starting point is 00:16:23 No, it wasn't based around a real fire. It was a cheeky developer that decided that Oh, so it wasn't even based around a real fire? so that was like a recipe for disaster so they wanted i guess they wanted the error message to be a little bit eye-catching so if you get an error message pop up and says your printer's on fire well you're gonna go take a look at it probably sooner than later wow that seems i don't know if it's unethical or or i don't know it's it's a bit bold or alarming i think it was supposed to be but yeah i i thought that that this error would turn out a lot differently. I thought that there would be an actual fire involved somewhere. So I worked with this guy. Oh, now I forget his name.
Starting point is 00:17:12 He was an engineering manager, but he had gotten a start in tech doing support. And in the 80s, he was doing support for this company that sold printers of some sort. And he told me a story that he, like he didn't mention this printer is on fire error message, but he said that they had sent out like some sort of bad driver at some point that like was doing something strange, like just like running over the same spot. Like instead of like advancing the printer,
Starting point is 00:17:41 it was just like printing repeatedly over the same spot. Oh, really? And that it could cause the paper to burst into flames or start to smoke, right? So they were getting all these calls. And he was support, right? And saying, oh, my printer, something's wrong. It's just going over and over again. And he had to say, okay, well, is there any smoke?
Starting point is 00:18:02 And then people would be like, that's a weird question to ask. Why do you ask? And then he had to instruct them to like, to unplug it and take it outside, which like, they were very confused. Why? I don't want you to panic. Is there smoke? No. Okay. What I need you to do, think carefully, don't panic. Unpl unplug it and bring it outside immediately yeah he told me this story to kind of explain to me that doing support for software is sometimes like a thankless job but you know i don't think everybody has to face this thing where they have to explain to the customers that we we're trying to not burn your house down so please take these actions it was probably businesses at that point like i don't think many homes had computers with heavy duty printers but from from what i could gather like the earliest printers were
Starting point is 00:18:55 used in either academic or research kind of context nobody was kind of plugging these in at home to print things out so So can I still get this problem? Like, can I still get this error, printer on fire? I mean, imagine. It says that it's still in the Linux source code as of version 5.11.13. Nice. So if something happens with the printer that it sends a status code of online and check, both set to on, then yeah, that message would pop up.
Starting point is 00:19:26 It's also kind of proliferated from there because I think that there's a lot of messages, for example, in some kernel CPU code that a thermal failure can result in a message that like CPU number zero, possible thermal failure, and it'll say in brackets, CPU on fire, question mark.
Starting point is 00:19:52 So it became like a meme but like a kernel a kernel error message meme now i don't know like the the developer that put it in might have read about all of these like instances of the earliest printers when they were trying to make them go faster catching on fire so maybe he was like that's amusing i'll put that in the message. We don't know. Maybe we'll never know. It's a mystery. That's awesome. It's not as deep of an issue as Quines, I think. I think there is a lot more meat to Quines than there was to the Printer on Fire one.
Starting point is 00:20:19 But I mean, it's interesting. It's an interesting story. Yeah, that is interesting. So speaking of Quines,ines okay so we're going back twice so so next up the next one i grabbed from this cursed computer iceberg is called yoroborus the yoroborus yeah the snake that eats its own tail exactly yeah it's a ancient sign of infinity it's exactly that the snake eating its tail the yoroborusos, is an Egyptian symbol, I guess. Yeah, maybe for infinity. I'm not really sure.
Starting point is 00:20:49 But so the other thing that it also is, is a complicated type of quine has been given this name. The quine concept can be extended, right? So instead of just having this single recursion where the program returns itself, you can have multiple levels, which has been called the Ouroboros or Equine relay. So the way this works is that you have two programming languages. So imagine our Java program. When you run it, instead of printing out another Java program, it prints out a C++ program. So you run your Java program, it prints out a C++ program, then you run your C++ program. What do you think it prints
Starting point is 00:21:34 out? The JavaScript program? Yeah, the Java program. So now you have like two programs that like return each other. So now you have a loop. A loop of infinity. Yeah. Yeah. A loop of infinity. Right. And then like, once again, it doesn't seem like something that should be possible, but
Starting point is 00:21:54 it just uses the same trick. So, you know, you write your Java program. So you have like your top part and then you have your string and then you have printing the string. But now inside the string, instead of just like before our Java program had to contain itself inside the string. Now it needs to contain itself and also the C++ program. And so when you run the Java program, it's going to get the C++ part of that string and print that out but it's going to print that out with inside of it a string that contains the java program and the c++ program again it's still like the dna thing but it's like
Starting point is 00:22:32 if you don contained the dna of a human but also the dna of a polar bear and then like and then if you had a child your child would be a polar bear but then that polar bear child it would be your grandson so it's kind of like a weird that's the that's a great premise for a sci-fi movie a world where polar bears and humans the premise of like your your offspring is like a completely different species and like a whole kind of maybe a massive, like a civilization that functions this way where they, they switch. Like there's a big switch constantly between,
Starting point is 00:23:13 you know, one species being the majority and another, I don't know. It seems like a sci-fi based novel. Yeah. Like a weird society. And then like, yeah,
Starting point is 00:23:21 what are these two, what are these two groups and what is their different cultures? You could call the, you could call it quine. Yeah. And then like, yeah, what are these two groups? And what is their different cultures? You could call it Quine. Yeah, it's like the title. Exactly. Or Ouroboros. I think Ouroboros is already taken. I think there's like several books that are named that.
Starting point is 00:23:35 Oh, is there? It's more popular than Quine. I had not heard of Quine, but I have definitely heard of Ouroboros. Nice. So super weird concept. Like this is kind of uh stranger and and and more complicated than equine right and the weird thing about it if you think about it is uh that you have to when you write your java program you have to know what the c++ program is too because like
Starting point is 00:24:00 the java program needs to contain it like So it kind of makes writing these things complicated. But it gets more complicated than there, right? So that is like a two-step Quine Relay, right? Like one goes to the other. But there's this guy, his GitHub handle is MAME, like M-A-M-E. And so he has this GitHub repo called Quine Relay. And it says, the following is a Ruby program that generates a Rust program that generates a Scala program that generates dot, dot, dot through 128 languages in total until it generates the original Ruby program again. 128 programming languages. I guess you could have n number if you knew the pattern on how to do it, right?
Starting point is 00:24:44 You could have n number of languages in between. I didn't even know there was 128 programming languages. Like, that's a lot. That does not surprise me, like, at all. I did not even blink when you're like, 127 programming languages. But if you think about it, like, so I vaguely heard of this before, I think. And I was like, that's strange. How does that work?
Starting point is 00:25:05 And now I guess I kind of understand how it works, but I think that makes it more amazing. So that means that like the first Ruby program has to have in some giant string, all 128 other programming languages, right? Inside of it. And then like every step needs to to be the same like every every result needs to contain like the proper result of all the other results there's got to be some
Starting point is 00:25:32 kind of method he has of kind of putting them in more than just one string because the string has limitations like you you couldn't put a infinite amount of stuff in one string yeah and like if different languages have different ways of delimiting a string, then that gets complicated, right? Like some symbol you want to show, you want to have your Ruby program in a string, but the symbols for a Ruby program string conflict with something else. Yeah, like the technical challenges there are interesting.
Starting point is 00:26:02 So somebody asked on the GitHub issue for this Quine relay, they opened a issue. I don't think this is really issue appropriate, but they said, how long did it take you? And he answered, he said, infinity, of course. I wrote the first program in Ruby. And then I wrote the second program in Ruby that produced the first one, repeat that through a hundred languages. Then I wrote the third program that produced the second one, and I kept repeating until I reached a fixed point. What you see is the infinieth
Starting point is 00:26:31 program, which comes from beyond the event horizon. Apparently, MAME is from the future or from some singularity that's been created by self-reproducing programs. It's not really clear.
Starting point is 00:26:48 That's awesome. I like how he's got a sense of humor. All right, so that was my second one, which is a Quine Relay. Does it count as a second one? I don't know. I think that it's pretty much the same one, just like part two. Yeah, we'll just wait. I think you're going to see a theme here.
Starting point is 00:27:04 Is there like a third one? Is this like, was that like two towers and we're going to watch Return of the King? Are there three? It's going to keep going. The further down the iceberg you go, the more quines. The more quines? I'll kind of break us away from quines just for another quick one. This one is also, I think, gave me a chuckle. The thank you for playing Wing Commander message that happens when you play Wing Commander and you finish the game. It kicks you back to the command prompt and it says thank you for playing Wing
Starting point is 00:27:36 Commander. Wing Commander is a video game in which you take control of a spacecraft and fight in a fictional fictional world against aliens and they're also allies it's it's kind of like a kind of first person you're in the cockpit flying in space doing missions shooting things there was also a big story component to it as well it was almost like you like an rpg and the fact that there was like a story playing out but like all the action was you in the cockpit. I know later wing commanders had you like walk around the, the flight deck of the carrier and you could talk to different people. And later on you can make choices and it became more RPG like the,
Starting point is 00:28:18 as the series went on. But like the first one was pretty much just flying around shooting things. And just looking it up here. But it was a, yeah, it was a, it was a pretty big game for the era. It was pretty groundbreaking when it came out. It was very popular. It seems like fegly Star Wars-y. Like your X-Wing versus TIE Fighter type game.
Starting point is 00:28:38 Yeah, but Wing Commander had its own world and its own world building and everything and its own characters. Anyway, yeah, so Wing Commander was a very popular game and it was in like the mid 90s and the the game designer creative director of wing commander was chris roberts who heads up cig games and with the star citizen project that's very controversial anyway so like Wind Commander was like the first game and Ken Demarest was the programmer and they were having like they were having issues because there
Starting point is 00:29:10 was an EMM386 memory manager issue error that would kick you out to the console at the end of the game. And he didn't know why. And it's not
Starting point is 00:29:19 unheard of because a lot of games in this era were trying to do a lot with limited limited memory resources. So there was all sorts of tips and tricks of games in this era were trying to do a lot with limited memory resources. So there was all sorts of tips and tricks and weird hacks that they were trying to do in order to get these games to run on limited hardware. And you know how production deadlines can be,
Starting point is 00:29:36 he didn't have time to figure it out. So all he did was he hex edited the error message so that it would say thank you for playing Wing Commander instead of EMM386 memory manager error. Nice. Which is like, I mean, that made me chuckle. So where is the error coming from? Did he edit it? He never found out. I think that once they shipped the game, it was fine.
Starting point is 00:30:02 It only happened when you had finished the game. So you had completed it anyway. You got kicked back to the console and said, thank you for playing Wing Commander. Nobody really thought anything of it. So it didn't matter anymore. It was shipped. He went off to work on a different project called Bioforge,
Starting point is 00:30:18 which was one of my favorite childhood games too. It gave me a chuckle because it's definitely one of, like, I know i've been in that situation where you know you're on a timeline you can't figure it out you got to move on to something else so you make the best of a bad situation and he just hex edited error message and i was sympathetic with him in that in that moment have you ever had a similar situation where you hacked something together to get it fixed like didn't really fix it no i don't think like i might have done that
Starting point is 00:30:46 while I was in the middle of trying to fix something else. But I don't think that I've ever deployed anything. Definitely not like production system. Okay, there's something that I can think of from when we worked together. It wasn't you, but let me, it comes right to mind. It wasn't me. Okay, see if this rings a bell.
Starting point is 00:31:05 Okay, okay. A printer page that wasn't working and there was a bug with it. Oh yeah, no, I know this story. All right, so tell the story, man. So in this particular product, there was a report. You would run the report and you could print it and there was a button and you would print it. So yeah, it would rerun the report again
Starting point is 00:31:26 instead of just formatting the output it already had. It would get that output data again and then it would format it so that it was printer friendly. I've tried to forget this, okay? And then like Adam brings it all back. I've like taken that and just kind of shoved it in a box and tried to forget about it. So the issue was that the report actually had an error
Starting point is 00:31:43 and the person fixed the report, but the printable version was still broken, and they didn't know why the report was running, but the printable version wasn't. So they pushed out the fix to the report so that you could use it again, but the printable version, he just took the button off. He's like, well, you can't print it, but it works now. And I think that was acceptable for it to be released so that people could use the report because it was broken. And now it was like it was a step up, right? Because you couldn't run the report at all. And now you could, but you couldn't print it. You have a very charitable interpretation.
Starting point is 00:32:14 My interpretation involves actually the lag time involved in bugs, right? Where it was like you knew that this thing would come back, but it might not land on your plate, right? So it's like I can put this out, right? Where it was like, you knew that this thing would come back, but it might not land on your plate, right? So it's like, I can put this out, right? And it'll get out there. You know, like code reviews were not really an important thing, right? So you could get this change out. And then like that person who was complaining would get the report to run, but you would know that like a week from then, or somebody would be like, where's my print button? And there'd be a new bug in, but it would land on somebody else.
Starting point is 00:32:49 That's what happened, yeah. The client complained. Yeah, that second iteration, it landed on you and then you went and went spelunking through source control and were like, what happened? Where's the print button? And then you just saw the commit
Starting point is 00:33:03 that was like fixing da, da, da, da, da. And it just like deleted it. Yeah, no, that's exactly what happened? Where's the print button? And then you just saw the commit that was fixing da-da-da-da-da, and it just deleted it. Yeah, no, that's exactly what happened. I never got to talk to him about why he did it. They were a different team in a different time zone, and we didn't really speak. Probably part of the problem right there. It was more like, well, this is my issue,
Starting point is 00:33:22 so I've got to figure out how to fix it. And I went through the code to see, okay, well, did it ever have a print button? Because that's the thing, there was no print button there, and that was suspicious. It's like, well, they're complaining about a print button not being there. It's like, well, maybe there wasn't one, because there clearly isn't now. Like, surely, no one just removed it.
Starting point is 00:33:41 Yes, somebody did remove it as part of a fix to the report. It's one of those times where you think the customer is crazy. You're like, you know, didn't support vet this? Like, oh, somebody said, hey, there's a button missing. Like, yeah, we're not going to remove a button. What are you talking about? What are you talking about? I would never.
Starting point is 00:33:59 No one would do that. We started off with Wing Commander. Yeah. Yeah. Okay. So what is it my turn now i guess yeah that like that was all there was to that to that issue is just that the guy hexed it in their message because he didn't have a great hack right and like it doesn't really have it doesn't
Starting point is 00:34:16 really have ramifications necessarily like like the print button i mean i guess if you wanted some really cool like finishing the game screen and you can't do that. But otherwise, there's no ramifications. Yeah, I remember playing Wing Commander and getting that message, but I just thought it was done. Games in that era were sometimes wonky, and you just kind of rolled with it. All right, so me, the next one I got is Polygot Computing. Yeah, the Wikipedia page is called Polygot Computing,
Starting point is 00:34:44 but I'm going to call it Polygot Computing. Yeah, the Wikipedia page is called Polygot Computing, but I'm going to call it Polygot Code. So this is going to seem a bit like a quine again. So Polygot Code is code that is a valid program in more than one programming language. So it's like you have a file, and you can run it as a Java program, but you can also run it as a C sharp program or something. Actually, those are very similar to each other.
Starting point is 00:35:10 So the one on Wikipedia is the program is a valid C program, but it's also a valid PHP program. And does that mean like the syntax that's used in it is interpretable in both languages the same way? So the way this works is with a lot of horrible tricks. So it's like, in some ways, a more complicated puzzle than the Quine one. So, you know, C has the preprocessor
Starting point is 00:35:35 where you can say like, you know, if def verbose is greater than two, like printf this message or something, right? And so that allows you to kind of intersperse. That's commonly done just like, hey, we want to have a verbose mode where we print lots of log messages. But you can do all kinds of things with the preprocessor, right? You could say like pound define paren equals return or something, right?
Starting point is 00:36:02 And all of a sudden, all your left parens are actually return statements, which would just make your program like very hard to understand, but, but, but it, it's still a valid C program because it kind of runs as a, as a first pass and rewrites all these statements. Right. So the interesting thing is, is that this like pound sign or hash symbol, I don't know what people call it now, but like that's also a comment in like in many languages, right? If you put down a pound sign, then that's often a full line comment. So you can just use this trick to do a lot of weird things, right? So you could put a whole bunch of defined statements
Starting point is 00:36:40 that change things that are commonly found in a PHP program to actually be translated into something that are commonly found in a PHP program to actually be translated into something that's commonly found in a C program. And the PHP program will ignore all those as comments and just run normal PHP, but the C program will translate that PHP program using the preprocessed macro back into a C program. Coming up with one of these would be very difficult,
Starting point is 00:37:06 right? Yeah, it's one of those mental puzzles again. And so you could imagine having a Python program, right? And then at the top of it, you have all these preprocessor macros that Python will ignore because
Starting point is 00:37:21 they're comments. And they actually change the Python program. Like they actually rewrite, you know, arbitrary Python to BC. So then you can now write stuff. I don't know if this is actually possible, but like you,
Starting point is 00:37:34 you can now write Python code and when you run it, you can run it without a Python interpreter. You can actually feed it into C because your preprocessor macros are in fact acting as a weird compiler and compiling your Python like down into C because your preprocessor macros are in fact acting as a weird compiler and compiling your Python like down into C. Yeah, that's, that's cool. You certainly wouldn't be able to bring in any libraries or anything like that, but, but yeah, this is poly got code. And in that case, you're kind of doing things that have the same output, but often poly got code. They, they don't do that at all. So they actually have two programs
Starting point is 00:38:05 that do two different things and use some tricks to do it. So there's a programming language called Whitespace. It's actually written by Edwin Brady, who I interviewed on this podcast. I think it was more of a joke thing that he produced. So in Whitespace, the only input to it are various forms of Whitespace.
Starting point is 00:38:23 So like a tab or a space or like a carriage return or a new line. Any other input is ignored. So like any characters that aren't whitespace are basically like comments. It's kind of like the inverse of what you would normally expect, right? Because normally compilers ignore whitespace and now that's the only thing. Yeah, which makes it fabulous for this polyglot code thing, right? So you can write a program that does whatever.
Starting point is 00:38:47 And if the language is not whitespace specific, then you can encode whatever whitespace program you want into however you space out that program. Yeah, so there's like the same program, but it's encoded all in the negative space of your actual code file. Yeah, or it could be a completely different program, right? Like you could, you know. Well, if you want it to be a Quine.
Starting point is 00:39:08 If you want it to be a Quine, then it needs to output itself. That would be interesting. So Polygot Quine. So it would be two languages. So each program can be run as two languages at once. And then they both have to output the exact same thing twice. Yeah. And then maybe you can add a polygons Quine relay.
Starting point is 00:39:27 So then it's like, it's always two languages that produce two other languages that produce two of them. Oh, now you've just tied together all three of your ideas into one thing. Wait, wait, I'm going to keep going here. So then, are you familiar with CodeGolf? No, no, I'm not familiar with CodeGolf. CodeGolf has very little to do with code golf no no i'm not familiar with code golf code golf is has very little to do with with normal golf right code golf is usually like they give you some sort of programming challenge like you know given a list of numbers you know like add them up and print the
Starting point is 00:39:57 result but but the challenge is to do it in as few characters as possible so it's like it's golf in the sense that like a low score, the lower the score, the better. So it, you know, it leads to some very unreadable code, right? It's just like, you want to get rid of all the white space. You want to jam everything together. Yeah. And so like Stack Exchange, like the Stack Overflow site, they have like a sister site. That's a code golf site where people post,, like they're just kind of using the stack overflow format, but for a different thing. So they'll post like a question and then people post as answers, like their, their CodeGolf solutions. And they have all kinds of strange, like this type
Starting point is 00:40:35 of puzzle thing is kind of right in their wheelhouse. So, so on there, somebody posted this, this following challenge. Add a language to a polyglot. This is an answer chaining challenge in which each answer builds on the previous answer. I recommend sorting by oldest thread in order to be sure about the order in which the posts are made. The task, the nth program
Starting point is 00:40:55 submitted to this challenge must run n different languages, specifically all languages added in the previous answers, plus one more. The program must output one when run with the first language used, two when run with the second, and so on and so forth. For example, the first answer could print one when run in Python.
Starting point is 00:41:15 The second answer could output one when run in Python. And then two when run in JavaScript. The third answer would be one run with Python, two with run in JavaScript, three when run in some other language. Like the first guy has it easy. You just write a program that prints the number one. Yeah. Okay, so the first guy, that's easy.
Starting point is 00:41:32 So, okay, I just print out in Python, like print one. Second guy, maybe this white space language we were thinking of, like maybe that could work. Third, I'm trying to think. I have a suspicion that the responses to this are not, there's not a lot of them. Because it gets harder as it goes. So I'm pretty sure that the responses
Starting point is 00:41:52 kind of top out around maybe five or six. Because yeah, after whitespace, maybe you could do the whole preprocessor thing we were talking about. So you use these predefined. Yeah, after that, I kind of run out of ideas so the thing that i found said that they had 101 wow that is way more than i thought there would be yeah it's crazy so i'm looking now at the hundredth so the hundredth is using a program a programming language called brain bool which i've never heard of there's definitely at least at least 144
Starting point is 00:42:27 by the by the looks of it yeah and i could keep scrolling but i can't tell so that's that's crazy it does seem like a lot of these languages are are ones i've never heard of like like somebody created a programming language specifically for the purposes of embedding inside of, of answering this question. I mean, which is what you haven't heard of brain bowl. Come on. So that's not exactly a quine, but, but it's very quine, quine related. Okay. So here's my next one. There is something called the actual, actually portable executable. So why, why can't a program that's created for my mac you know run on your windows computer it's because the architectures are different but like if we both have like a an x86 like intel cpu like it has the same architecture oh apple's not doing that anymore well mine is okay you have an old-fashioned one.
Starting point is 00:43:26 Okay. That's actually news to me. I didn't know those things because I thought that they would have been able to execute the same instructions. Well, so the interesting thing is the CPUs can execute the same instructions, but it's like the operating systems are different
Starting point is 00:43:39 and have different assumptions, right? So if I take an an exe file from Windows and I put it on my Mac and I like double click on it, like it won't know what to do with it. It'll say like, this is not the format that I expect an executable to be in, right? Okay. Like just the Mac and Linux and Windows
Starting point is 00:43:58 have different assumptions about what an executable should look like, right? Like just imagine like headers at the top that says like Windows executable or something, right? And so if it doesn't, if a file says... It's like when the browsers all have their different engines, right? Like they would all take a different look at client-side code and interpret it differently.
Starting point is 00:44:17 Yeah, yeah. And then another problem is like, obviously if you were trying to pop up like a Windows dialog box, whatever like system calls you would make to do that, like they're obviously not going to work on my Mac. On Linux, there is what's called libc, also on my Mac and probably also on Windows too, at least under that whistle.
Starting point is 00:44:37 It's like the old school standard library for C. It's been around for a long, long time. And so that's another limitation is that if I'm trying to run something from Linux that's on Windows and it tries to call like the libc program that opens a network socket or something like that just doesn't exist.
Starting point is 00:44:53 Unless, yeah, you're running under Wizzle. But so this person named Justine Tooney found this, came up with this little trick, right? And it's a little bit like our poly Polygot code. So the thing she found is that whatever the headers that go at the top that tell something that it's a Windows executable, that you can put those at the top of a Unix shell script and the shell script will ignore them. So it's a bit like a Polygot code, right? So it's like you put the headers that say, this is a Windows executable.
Starting point is 00:45:27 And then below that, you put a Unix shell script. And then so on Windows, you have a normal Windows executable. It has the header, it skips the shell part, and it just starts executing the program. On Linux, it contains the shell script. And what the shell script says is to like reopen the program itself and it makes
Starting point is 00:45:47 some changes to it um so that it's now a properly formatted linux executable and then it launches it okay so what she in fact did was find a way to make an executable that's kind of like this poly got code one is the unix shell and then the other is the Windows headers. And then you're right. When you get down to the CPU, like when you get down to the machine code, if you have the same CPUs,
Starting point is 00:46:12 like the same instructions will do the same thing, right? It's all that other stuff, like the system calls and the headers and whatever. Whatever changes she has to make to that executable to make it compatible
Starting point is 00:46:22 would mean that like you would have to ditch all of the operating system specific make to that executable to make it compatible would mean that like you would have to ditch all of the operating system specific code of that executable because I mean there's no way that you can open a Windows dialog on a Mac. Yeah exactly so she says that this is only good for like standard in and standard out and opening sockets so you would have to like build up everything besides that yourself. But even those things, like even opening a network socket is different across Mac and Linux and Windows, right? Certainly across Windows and Mac, they're different. So she made like a small translation layer, basically something that looks like this libc, but that can run on Windows. And so basically she ends up with this big command
Starting point is 00:47:07 that she can pass to the C compiler and it makes it produce these executables that are valid on all three systems. I don't know who she is, but maybe she was part of this Polygot code competition and she was like, wait a minute, if you can encode, if you can make something. I'm going to come up with a practical use for this.
Starting point is 00:47:26 And it is very practical, maybe. I mean, I'm not sure how stable it is. Like if one side changes, like all of these portable code things are dependent upon like, you know, very exacting interpretation. Like ignoring certain things and interpreting other certain things and understanding them exactly. Right. But pretty, pretty cool usage of this format. Like the program that you write that's going to be interpreted by the three different operating systems is going to be pretty narrow in scope. Yeah, but it's a use of of this polyglot code. So these things like do have practical use, I guess, if you can you can call that practical.
Starting point is 00:48:04 And then, okay. Oh, here we go. The big finale. So I interviewed before Brian Kernaghan. So like Brian Kernaghan, who I interviewed, and Dennis Ritchie and Ken Thompson and a bunch of other people, I guess, they created Unix and the C programming language at Bell Labs, like back in the 70s. But Ken Thompson definitely created a lot of what became Unix, which like, you know, almost all modern computers are now based on. And he also created this B language. And then and then Dennis Ritchie created this C language, right? And so the C language is kind of responsible for all the like C type programming languages we use, right?
Starting point is 00:48:43 You're writing things in Scala, It's running on the JVM. The JVM like runtime is probably written in C++, which is like an extension of C. So at some point when you run a program, like C is involved somewhere. All roads lead to Rome. Yeah, so somewhere C is at the base, right? Like your Scala program is great and fancy and all,
Starting point is 00:49:02 but somewhere there is like a runtime that it runs in that was written using C. It's the base layer, right? So Ken Thompson, like he got a Turing Award for his involvement in Unix. And he gave this talk called On Trusting Trust, right? And so there's a talk and a paper. It's kind of, it's very whimsical, I guess,
Starting point is 00:49:22 but it's also kind of like a punch in the gut. Because what he was trying to say is that you can't trust computers. You can't trust computer programs that you haven't written yourself. And when he meant written yourself, he meant written yourself at the level of assembly. And so he showed why. So the base C compiler that compiled the C++ that compiled the JVM machine that runs your Skeletor, it has to be compiled itself, right? Like that C compiler has to be compiled. Yeah. So, I mean, what are you going to compile that in? So like you need another language to do it. So at some point you have to like bootstrap this process, right?
Starting point is 00:50:07 You need like a base compiler that can compile the first version of C. Yeah, like the proto compiler, the compiler of all compilers. The very first C compiler was written for, I think for this old machine called the PDP-11. And they had to write the C compiler for that using PDP 11 assembly. So they had to use the machine instructions of that particular CPU to build the C compiler, right? And then once they had that, they could compile C in it. And you can imagine a similar process happening for every new CPU architecture, right? There is ways to cross compile. So that doesn't necessarily have to happen on every new cpu but like basically
Starting point is 00:50:45 at some point you know this base compiler is compiled and then further versions are compiled from that so it's like a chain right and if you're thinking this sounds a little bit like a quine then then maybe you see where we're going here right i thought i knew we'd get to that yeah basically i looked at this list and i started reading through things and there was a lot of quines there. It sounds like you read an article about quines and you really like them. And now everything is a quine. Exactly. So Ken proposes this exploit, right, in his paper.
Starting point is 00:51:20 So the first thing is he says, OK, c compiler because okay i'm getting an award for for creating unix and you guys all think it's great but how can you trust it right he's like so in my c compiler i can put uh this line right and it says you know whenever you're at the login screen and you're checking the password just also check for this other password right just like hard code in ken's password into the login the. The super user backdoor. Yeah, right? And so every, you know, Unix is compiled using C. And then so every Unix implementation that uses that compiler will have that backdoor, right? And you wouldn't be able to find that.
Starting point is 00:51:57 Like if you looked at the Unix source code, you wouldn't be able to see the backdoor, right? Because the backdoor isn't actually in the operating system source code. It's in the compiler. So you can't see it, right? It adds it in during the compilation. Yeah. So, but you can look at the compiler and see that that backdoor is there, right? So if you read the source of your compiler, like, I mean, I don't tend to do that. Chances are somebody has, and somebody would have been like, Hey, what's this all about? And like, you know, there would have been an article about it would have been, you know, there would have been a bunch of news you'd see in headline on like tech radar. Exactly. Right. So it's, the paper is called reflections on trusting trust. And yeah,
Starting point is 00:52:39 it was in 1984. So he called this first thing where he's just going to put in this thing that always checks for his username. He called this a Trojan horse. And that since became kind of an industry standard term. I mean, he didn't invent the horse of the Trojans. But he applied it to computers and gave it this term, right? So it's like, this was a trick that he's embedded in the source code, right? But yeah, as you say, you can just go and look at the C compiler and see that that's there, right? So this is where he gets a little bit tricky, right? So the next idea is,
Starting point is 00:53:20 hey, what if I add something to the C compiler that can tell when it's compiling the C compiler? Because as we said, the C compiler has to be compiled, right? And there's this bootstrap process that leads all the way from the C compiler to your JVM, right? So the C compiler will look and tell when it's compiling itself, right?
Starting point is 00:53:44 And when it's compiling itself and it's producing the assembly code, then what it can do is you can take the assembly code that Ken's original Trojan horse would generate, and the compiler can detect whether it's compiling the C compiler, and it can add in that code. and it can add in that code. So it'll add in that assembly. It's one level removed now. It's one level removed now, right?
Starting point is 00:54:11 So now if you could take the C compiler, you could remove the backdoor, but you compile it with a version that has this level that adds it in. And now your result, like the source code won't have the backdoor, but the backdoor will be in the result, right? But like this bootstrap process continues, right? So the problem is like the step after that, when you have another C compiler, right?
Starting point is 00:54:36 So when you compile that C compiler again, then like you're going to lose it, right? So the trick that we need here is something like a quine, right? We need some way to like reproduce this change. So what he comes up with is we need to detect, as we said, when we're compiling the C compiler so that we can put in this assembly
Starting point is 00:54:58 that is the Trojan horse, right? But we also, once we're detecting that we're inside of a C compiler, let's also insert the code of ourselves back in as assembly code. You add in this code to your compiler that adds in the Trojan horse and adds in the code that adds in the Trojan course
Starting point is 00:55:17 and re-adds in itself, right? When you compile something with that, you can take out all that nonsense, but it'll get added back in, right? And every time after that, whenever you compile it, it will be there in the assembly, but it'll never be in the source code. Right. So he gives this talk.
Starting point is 00:55:37 Unless you read all the compilers. You would have to be able, yeah, you'd have to go back to the base one and check it, right? So it illustrates this point that you can't trust it unless you're at least aware of all of the code between you and the actual assembly. Yeah, you can't just look at the source code of your compiler. You have to look at the source code of your compiler's compiler
Starting point is 00:55:58 and all the way back, right? And this is a scary thought, but I think it's especially a scary thought because this was a talk given by the guy who who built the c compiler and built unix so so like in a way i'm pretty sure that after that talk a bunch of people started looking at compilers in a way wait a minute the guy who made it said that he could put whatever he wanted in it. We wouldn't know. We got to go look. Yeah. Yeah. In a way, he was saying like, you know, I didn't do this, but how would you know if I did? It would have been very easy. That's all I'm going to say.
Starting point is 00:56:36 So before Unix, there was this project called Maltics. Yeah, the Brian Kernan podcast that I did, you can listen to it here about more. It was kind of somewhat of an unsuccessful project, at least not as successful as Unix. But they were trying to get the military to use it, I guess, and the military did some sort of audit. And at that time, operating systems of this nature were like kind of a wild, crazy concept, right? And like one of the audits from the military actually suggested this as a potential problem. They're like, okay, this operating system is great and we can audit the code,
Starting point is 00:57:09 but how do we know that there isn't something in here from the thing that it was compiled with? So actually, in fact, Ken didn't come up with the idea himself. And I think it shows that quines are, they're practical somehow. Like maybe not, they don't come up all the time, but there is uses for them and very odd uses, right? Like this is a, this is an assembly level quine where it needs
Starting point is 00:57:31 to reproduce itself using assembly, you know, generation by generation. Actually, I don't think there's a lot of uses for quines, but I think that when there is, there's probably something really powerful, right? Like something really strange and and odd if you let adam talk long enough he'll talk himself out of a point he was trying to prove it's like i think that you know coins can be very useful but you know maybe not yeah i don't know how they're useful but there's something weird here right very specific yeah it's like it's like something like a lot of times we think about, you know, computing, you know, like what's the best way to like present this problem, right? Or what's like the fastest way to solve this? And clients have a, like they have a totally different perspective on computation, right?
Starting point is 00:58:18 Like the success of my program is not the result or it's not how beautiful it is. It's actually how it like self-replicates. Like it's a very different perspective. Yeah, like I didn't get into computer programming because I knew it was gonna be a really good job or anything. It was kind of a fluke. I kind of got into it because I took a class
Starting point is 00:58:43 where we were, it was like a class in high school about programming. It was in like Turbo Pascal and we just like built things, right? And they were fun and we built like little games. Yeah, I had a similar class with object-oriented Turing. Oh, there you go, right? I think I had one with Turing too, which is like, I think it's a weird programming language that they only used like in Ontario in like the nineties. Like it's, it's very obscure. Specifically only for grade nine high school students. Yeah. It didn't take the world by storm, but yeah, man, it was fun. And like, I feel like there's, um, I don't know, these like quines, they kind of make me think back to this time of
Starting point is 00:59:25 just like building fun things. Like, I don't know, just like so much of like stuff about computer programming is like, Oh, what's the best way to scale some giant service? Or what's the best way to represent business requirements? Or like, how do we be truly agile? Or like, it's all like, who cares? Right? Like, I just want to do the cool stuff. Like I want to make, but just the idea of code that you can make reproduce, like after the source code's gone, like that's insane. Right. I'm going to write this thing and then delete the code. And then it's still going to persist. Like that's a wild idea. That is, that's, that's pretty crazy. Yeah. And so like, I don't know what the practicality of any of this is, but it's like, it's kind of, it's kind of beautiful in a weird way. Like, I think that, you know, one thing I always wanted to do with the podcast that I probably haven't done as much as I who made his like 128 programming language like loop like that that is a very like you know he's doing it for some sort of weird aesthetic kicks or
Starting point is 01:00:34 something right like this isn't nobody's paying him do you know what i mean like yeah yeah no i i i hear you um it's it's kind of like back when I started just building small programs that did weird things or the unknown, right? Like trying to feed something into something and seeing what happened. I know, right? Just build weird things and have fun.
Starting point is 01:00:59 Yeah. So this seems like a good place to end things. So if you're listening, you know, build weird things. And subscribe to the podcast and to the newsletter, which I'm trying to start. I haven't sent out any newsletters so far, but I will. And if you like this episode, let us know. And we can decide whether we should do more like this in the future.
Starting point is 01:01:20 And until next time, thank you so much for listening.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.