text
stringlengths
0
1.82k
**Brian Ketelsen:** I wanted to bring up almost the same point, but from the opposite direction. I've only ever done Git from the command line, and I was in Windows the other day and needed to do a Git operation, and I had the GitHub client, GitHub Windows application, and I opened it up and I couldn't understand how t...
**Erik St. Martin:** I've been in that boat, too.
**Brian Ketelsen:** All I wanted to do was merge master into my branch so I could make sure that it worked, and I clicked buttons but I could not figure out how to just merge master into my branch, and I was getting really frustrated. So it's almost as if those layers of abstraction take away the power of the tools tha...
**Carlisia Thompson:** And everybody who designs a visual tool has his visual aesthetics, and each visual tool is going to be different and you have to learn it, whereas with the command line, usually the commands have a certain commonality, like UNIX-themed, and you can sort of figure out the commands from one tool to...
**Thorsten Ball:** Yeah, I'm not against graphical interfaces. Some are vastly superior to their command line equivalent. They give you a much better understanding. The best example would be viewing your Git commit history. In a graphical interface, that gives you a much greater understanding and a lot more power, and ...
I think you also have to really draw the line somewhere, because if you keep digging and if you keep breaking open those black boxes, I don't think you're gonna come away super healthy, right? \[laughter\] You're never gonna get done, and...
**Erik St. Martin:** All I need to do is send an email, but I need to understand how a NAND gate works. \[laughs\]
**Thorsten Ball:** That's right, yeah. Look, one and a half years ago, two years ago I tried to understand how CPUs work. Then you dig into CPUs and you understand kind of what they do, and they fetch instructions, and they decode them, and then they execute them, and they talk to memory, and I/O devices and so on. And...
**Erik St. Martin:** There's just not enough time to learn all of it either.
**Carlisia Thompson:** And that brings up a good point, too... I was like this earlier in my programming life, trying to just use one tool for a particular thing, and there's absolutely nothing wrong with using multiple tools; there's nothing wrong with using a couple IDEs, one to do most of the stuff and one to do oth...
**Thorsten Ball:** \[20:03\] That's certainly true, yeah. That's exactly what I meant. As I said, you have to decide what to look into, and you have to decide how much time you're gonna spend. What I'm saying is if you're trying to understand those levels below you, and even if they at first might not seem related to w...
**Erik St. Martin:** Yeah, and I think it's important to choose your battles, too. We've only got so much time and mental capacity to learn these things, so I think it's okay to take the easier abstractions on the things that you don't care about so much, but maybe don't on the things that are going to help you succeed...
**Thorsten Ball:** Yeah.
**Erik St. Martin:** I think it's about time to take a break, and when we get back we really wanna start talking a little bit more about your book, and all that good stuff. So let's take a quick break.
**Break:** \[21:15\]
**Erik St. Martin:** And we are back, talking to Thorsten Ball about his interpreter book, Writing an Interpreter in Go, which has been really interesting.
**Carlisia Thompson:** Thorsten, I was looking at the blog post from Steve Yegge, the Rich Programmer Food blog post that you mentioned, and it's absolutely fascinating. I haven't gotten to the end yet, but he talks in detail in a very funny way about why the need for learning about compilers. He also mentions that not...
With that, I wanted to start talking about what exactly is an interpreter and a compiler, how they work and why are they the building blocks, and what makes it such a big deal and useful for us to know about them?
**Thorsten Ball:** \[23:47\] Yeah, that's exactly the point you make. I think it's really funny because a lot of people, they... What you said is absolutely correct - the market of compiler writers is a small one. You don't see many advertisers or recruiters sending out emails like "Do you wanna write a compiler?" But ...
The basic idea behind a compiler is it takes input, which is programming code or code, and it takes this input, transforms it and puts out something the computer can understand and execute. You take puts "Hello World" and give it to a compiler, and the compiler outputs machine code. This machine code is much longer tha...
In the end, it's the same idea - you take source code and output something that a computer can understand. It does this by first parsing the input; it most of the times constructs an internal tree, a syntax tree, and it then has several passes or phases where it takes this tree and tries to look at it in detail and fin...
**Erik St. Martin:** Yeah, it does.
**Carlisia Thompson:** Yeah, it makes sense.
**Erik St. Martin:** One of the coolest tricks I've ever seen with people understanding how a compiler works is actually from a security perspective.
**Thorsten Ball:** Right.
**Erik St. Martin:** I forget who this was that posted an article about this, but you could rewrite the source code of the compiler, compile the compiler with it, and then compile the compiler with it again, and then it would be in the compiler, but not in the source code. So now anything that you compiled with this ta...
**Thorsten Ball:** Reflections on Trusting Trust is the name of the paper, by Ken Thomson.
**Erik St. Martin:** Yes!
**Thorsten Ball:** It's super interesting and mind-blowing actually if you read it. It's like a science fiction short story on four pages.
**Erik St. Martin:** So let me ask this... Why an interpreter instead of a compiler? And a good question for some of the listeners may actually be "What's the difference between an interpreter and a compiler?"
**Thorsten Ball:** \[27:46\] Alright. First of all, the difference is an interpreter takes source code as input and executes it, and it doesn't leave anything behind except what the source code tells the interpreter to do. A compiler takes source code as input and produces something that can then be executed. For examp...
So the question is, "Is this a compiler, or is this an interpreter?" because it takes source code, it then compiles it to get machine code, and it then executes this machine code directly, just in time. The question is, "Is this a compiler or an interpreter?" I don't know what the answer is... They're called JIT interp...
The reason why I chose to explain how an interpreter works is because I think compilers are much more, let's say -- I won't say 'complex', but you have to do a lot more to get it working. I wanted to keep the scope of the book small, so I only chose to show how an interpreter works as a starting point. Because if you f...
The other thing is I'm not a compiler wizard, or anything. I'm not a compiler expert, and it's a topic that's still kind of intimidating to me because I don't know everything about it and I don't really know how those big compilers (like GCC) work. I'm starting to dig in... I tried to build a compiler for the Monkey la...
I think in the end it's not one or the other, because if you learn how to write an interpreter, you're perfectly well equipped to write a compiler afterwards. In my opinion, it's the first stepping stone to understand compilers better.
**Erik St. Martin:** I guess you would have to introduce some form of assembly language, whether that's your own made-up assembly language or an actual assembler. You would have to somewhat understand that in order to implement the compiler.
**Thorsten Ball:** Yeah, that's the thing. I love to talk about virtual machines, but I try not to get into them. You could build a compiler that outputs bytecode, right? And bytecode is something like made-up machine code; it's machine code for a machine that doesn't exist, and it's not as hairy as assembly language o...
\[32:09\] That's what you said, you have to understand assembly language and you have to understand what an assembler is, and what instructions are, and then you have to explain how the machine works. I don't know... The scope blows up.
**Erik St. Martin:** I was actually gonna recommend a book that I read a few years ago and I'm probably due to read again, that I highly recommend to people. It's very short, and I don't know whether you've come across this... It's called The Elements of Computing Systems.
**Thorsten Ball:** Yes.
**Erik St. Martin:** Yeah, they call it From NAND to Tetris. If you're interested in it, it's NAND as in NAND gate... Nand2tetris.com It's only about 300 pages, and this is kind of the shortfall of the book - because there are so many topics to introduce, it moves very quickly through boolean logic and arithmetic and g...
So now that your book has come along in a language that I'm super interested in, I kind of feel like I wanna reapproach that book and now read your book for a better implementation of that. It'd be kind of cool to start seeing some of the other areas implemented, too... You're talking about virtual machines and things ...
**Thorsten Ball:** Yeah, so this book is amazing. It's actually - and I'm not joking - what holds up the microphone on which I'm recording this. \[laughter\] The microphone is sitting on top of the book, right? I read this two years ago, and I have the exact same feeling like you just described. It's an amazing book an...
If you have this in combination with the book - a teacher that guides you along the way and gives you additional information and hints and tips and tricks and so on, this would be an amazing course to take.
\[35:53\] The thing is, there are few other books like this. If you look at compiler books, most of them have at least 600 pages, and everybody always recommends Dragon Book, and I think it has 900 pages. Those are books - their target audience is not you or me sitting at home on a Saturday evening, like "I'm going to ...
**Erik St. Martin:** I think for most of us that don't have large academic background, it's really that "source code or it didn't happen" type feeling.
**Thorsten Ball:** That's right.
**Erik St. Martin:** If I see a whitepaper on something, it's like, this is really interesting, but I don't feel like I have the academic background to look at the mathematical proofs and be like, "Yeah, I totally get this." It doesn't matter if it's just cobbled together code that isn't meant for production use, but j...
**Thorsten Ball:** Right.
**Erik St. Martin:** ...how does assembly language work in 15 pages..? I think my assembler book is like 900 pages, you know? So you kind of need a little bit of handholding, or at least some reference code that you can break and fix again and get a better understanding for how each of the pieces work.