Lex Fridman PodcastBrian Kernighan: UNIX, C, AWK, AMPL, and Go Programming | Lex Fridman Podcast #109
Summaries, chapters, transcripts, and FAQs on this page are made by uListen, not YouTube.
Partial transcript
75 min read · 15,006 wordsIntroduction
Lex Fridman 0:00 The following is a conversation with Brian Kernighan, a professor of computer science at Princeton University. He was a key figure in the computer science community in the early UNIX days, alongside UNIX creators Ken Thompson and Dennis Ritchie. He co-authored the C programming language with Dennis Ritchie, the creator of C, and has written a lot of books on programming, computers, and life, including The Practice of Programming, The Go Programming Language, and his latest, UNIX: A History and a Memoir. He co-created awk, the text processing language used by Linux folks like myself. He co-designed AMPL, an algebraic modeling language that I personally love and have used a lot in my life for large scale optimization. I think I can keep going for a long time with his creations and accomplishments, which is funny, because given all that, he's one of the most humble and kind people I've spoken to on this podcast. Quick summary of the ads. Two new sponsors. The amazing self-cooling Eight Sleep mattress and Raycon earbuds. Please consider supporting the podcast by going to EightSleep.com/Lex and going to BuyRaycon.com/Lex. Click the links, buy the stuff. It really is the best way to support this podcast and the journey I'm on. If you enjoy this thing, subscribe on YouTube, review it with five stars on Apple Podcasts, support it on Patreon, or connect with me on Twitter @LexFridman. As usual, I'll do a few minutes of ads now, and never any ads in the middle that can break the flow of the conversation. This show is sponsored by Eight Sleep and its incredible Pod Pro mattress that you can check out at EightSleep.com/Lex to get $200 off. The mattress controls temperature with an app and can cool down to as low as 55 degrees. Research shows that temperature has a big impact on the quality of our sleep. Anecdotally, it've been a game changer for me. I love it. The Pod Pro is packed with sensors that track heart rate, heart rate variability, and respiratory rate, showing it all on their app once you wake up. Plus, if you have a partner, you can control the temperature of each side of the bed. I don't happen to have one, but the Eight Sleep app reminds me that I should probably get on that. So ladies, if a temperature controlled mattress isn't a good reason to apply, I don't know what is. The app's health metrics are amazing, but the cooling alone is honestly worth the money. As some of you know, I don't always sleep, but when I do, I choose the Eight Sleep Pod Pro mattress. Check it out at EightSleep.com/Lex to get $200 off. This show is also sponsored by Raycon earbuds. Get them at BuyRaycon.com/Lex. They've quickly become my main method of listening to podcasts, audiobooks, and music when I run, do the push-ups and pull-ups that I've begun to hate at this point, or just living life. In fact, I often listen to brown noise with these when I'm thinking deeply about something. It helps me focus the mind. They're super comfortable, pair easily, great sound, great bass, six hours of playtime. In fact, for fun, I have one of the earbuds in now and I'm listening to Europa by Santana, probably one of my favorite guitar songs. It kind of makes me feel like I'm in a music video. So, they told me to say that a bunch of celebrities use these, like Snoop Dogg, Melissa Etheridge, and Cardi B. I don't even know who Cardi B is, but her earbud game is on point. To mention celebrities I actually care about, I'm sure if Richard Feynman was still with us, he'd be listening to The Joe Rogan Experience with Raycon earbuds. Get them at BuyRaycon.com/Lex. It's how they know I sent you and increases the chance they'll support this podcast in the future. So for all of the sponsors, click all of the links. It really helps this podcast. And now, here's my conversation with Brian Kernighan.
UNIX early days
Lex Fridman 4:25 UNIX started being developed 50 years ago, maybe more than 50 years ago. Can you tell the story, like you describe in your new book, of how UNIX was created?
Brian Kernighan 4:35 Huh. If I can remember that far back. (laughs) It was, it was some while ago. Um, so I think the gist of it is that at Bell Labs, eh, in 1969, there were a group of people who had just finished working on the MULTICS project, which was in self-follow on to CTSS. So, we can go back sort of an infinite regress in time, but the, uh, CTSS was a very, very, very nice time sharing system. It was very nice to use. I actually used it as that summer I spent in Cambridge in 1966.
Lex Fridman 5:06 What was the hardware there? Right, so what's the operating system? What's the hardware there? What's the CTS look like?
Brian Kernighan 5:12 So CTSS looked like, uh, kind of like a standard time sharing system. Certainly at the time, it was the only time sharing of note. (laughs)
Lex Fridman 5:19 Let's go back to the basic.
Brian Kernighan 5:20 (laughs) Sorry, Okay. In the beginning was the word, and the word- (laughs) So-
Lex Fridman 5:25 And then there was time sharing systems.
Brian Kernighan 5:27 (laughs) Yeah. If we go back into, let's call it the 1950s and early 1960s, most computing was done on very big computers, physically big, although not terribly powerful by, you know, today's standards, that were maintained in very large rooms, and you used things like punch cards to write your programs on and talk to them. So you would take a deck of cards, write your program on it, send it over a counter, hand it to an operator, and some while later, back would come something that said, "Oh, you made a mistake." And then you'd recycle. And so it was very, very slow. So the idea of time sharing was that you take basically that same computer, but...... connect to it with something that looked like an electric typewriter. They could be a long distance away, it could be close. But fundamentally, what the operating system did was to give each person who was connected to it and wanting to do something a small slice of time on, um, to do a particular job. So, I might be editing a file, so I would be typing, and every time I hit a keystroke, the operating system would wake up and said, "Oh, he typed a character, let me remember that." Then it'd go back to doing something else. So, it'd be going around and around a group of, uh, people who were trying to get something done, giving each a small slice of time and giving them each the illusion that they pretty much had the whole machine to themselves, and hence, time-sharing, that is sharing the computing time resource of the computer among a number of people who are doing it.
Lex Fridman 6:54 Without the individual people being aware that there's others, in a sense, the illusion, the feelings, that you have the machine as, uh, y- your own.
Brian Kernighan 7:02 Pretty much that was the idea, yes. You had, if it were well done, a- and if it were fast enough and other people weren't doing too much, you did have the illusion that you had the whole machine to yourself, and it was very much better than the punch card model. And so CTSS, the Compatible Time-Sharing System-
Lex Fridman 7:19 (laughs)
Brian Kernighan 7:20 ... was, I think, arguably the first of these. It was done, I guess, technically '64 or something like that. It ran on an IBM 7094, slightly modified to have twice as much memory as the norm. It had two banks of 32K words instead of one. So (laughs) -
Lex Fridman 7:39 32K words, yeah, that's-
Brian Kernighan 7:40 Each word was 36 bits so call it, you know, about 150KB times two. So, by today's standards, that's down in the noise.
Lex Fridman 7:49 Yeah.
Brian Kernighan 7:49 But at the time, that was a lot of memory and memory was expensive. So, uh, CTSS was just a wonderful environment to work on. It was done by the people at MIT led by, uh, Fernando Corbató, Corby, who died just earlier this year, um, and a bunch of other folks. And then, so I spent the summer of '66 working on that. Had a great time. Uh, met a lot of really nice people and indirectly, uh, knew of people at Bell Labs who were also working on a follow-on to CTSS that was called Multics. So, Multics was meant to be the system that would do everything that CTSS did, but do it better for a larger population, all the usual stuff.
Lex Fridman 8:31 Now, the actual time-sharing, the scheduling, uh, how much... What's the algorithm that performs the scheduling? What's that look like? How much magic is there? What are the metrics? How does it all work in the beginning?
Brian Kernighan 8:44 I- So, the answer is I don't have a clue. I think the basic idea was nothing more than who all wants to get something done. Suppose things are very quiet in the middle of the night, then I get all the time that I want. Suppose that you and I are contending at high noon for something like that, then probably the simplest algorithm is a round-robin one that gives you a bit of time, gives me a bit of time, and then we could adapt to that, like, what are you trying to do? Are you text editing or are you compiling or something? And then we might adjust the scheduler according to things like that.
Lex Fridman 9:15 So, okay, so Multics was trying to just do some of the, uh, clean it up a little bit.
Brian Kernighan 9:20 Well, it was, it was meant to be much more than that. So, Multics was the Multiplexed Information and Computing Service, and it was meant to be a very large thing that would provide computing utility, something that where you could actually think of it as just a plug-in-the-wall service, sort of like cloud computing today.
Lex Fridman 9:36 Yeah.
Brian Kernighan 9:37 Same idea, but 50 odd years earlier. And so, uh, what Multics offered was a richer operating system environment, a piece of hardware that was better designed for doing the kind of sharing of resources and presumably lots of other things.
Lex Fridman 9:56 Do you think people at that time had the dream of what cloud computing is starting to become now, which is computing is everywhere, that you can just plug in almost no- you know, and you never know how the magic works. You just kind of plug in, add your little computation that you need to perform, and it does it. Was that the dream?
Brian Kernighan 10:15 I don't know whether that was the dream. I wasn't part of it at that point, remember, I was an intern for a summer. But my sense is, given that it was over 50 years ago, yeah, they had that idea that it was an information utility, that it was something where if you had a computing task to do, you could just go and do it. Now, I'm betting that they didn't have the same view of computing for the masses, let's call it, the idea that, you know, your grandmother would be shopping on Amazon. I don't think that was part of it. But if your grandmother were a programmer, it might be very easy for her to go and use this kind of utility.
Lex Fridman 10:51 What was your dream of computers at that time? What did you see as the future of computers 'cause you have predicted what computers are today, in a sense?
Brian Kernighan 10:59 Right. Oh, short answer, absolutely not (laughs) . I have no clue. I'm not sure I had a dream. I- it was a dream job in the sense that I really enjoyed what I was doing. I was surrounded by really, really nice people. Cambridge is a very fine city to live in, in the summer, less so in the winter when it snows, but in the summer, it was a delightful time. And so I really enjoyed all of that stuff and I learned things, and I think the good fortune of being there for a summer led me then to get a summer job at Bell Labs the following summer, and that was going to useful for the future.
Lex Fridman 11:31 So, this Bell Labs is this magical, legendary place. So, first of all, where is Bell Labs? And can you start talking about that journey towards Unix at Bell Labs?
Brian Kernighan 11:46 Yeah. So, Bell Labs is physically, um, scattered around, uh, at the time, scattered around New Jersey. The primary location was in a town called Murray Hill, or a location called Murray Hill. It was actually the- across the boundary between two small towns in New Jersey called New Providence and Berkeley Heights. Uh, think of it as about 15, 20 miles straight west of New York City.... and therefore about an hour north of here in Princeton. Um, and at that time, it had, make up a number, 3 or 4,000 people there, many of whom had PhDs and mostly doing physical sciences, uh, chemistry, physics, uh, materials kinds of things, but very strong math and it... rapidly growing interest in computing as people realized you could do things with computers that you might not have been able to do before. You could replace labs with computers that had worked on models of what was going on. So, that was, that was the essence of Bell Labs, and again, I wasn't a permanent employee there, I was... that was another internship.
Lex Fridman 12:47 Yeah.
Brian Kernighan 12:48 I got lucky in internships. (laughs)
Lex Fridman 12:50 I mean, if you could just linger on it a little bit, what was the... what was in the air there? 'Cause some of this is, the number of Nobel Prizes, the number of Turing Awards and just legendary computer scientists that come from there, inventions including developments, including UNIX, is just, uh, is unbelievable. So, is- is- was there something special about that place?
Brian Kernighan 13:11 Oh, I think there was very definitely something special. Um, I mentioned the number of people, so very large number of people, um, very highly skilled, and working in an environment where there was always something interesting to work on, because the goal of Bell Labs, which was a small part of AT&T, which provided basically the country's phone service, the goal of AT&T was to provide service for everybody, and the goal of Bell Labs was to try and make that service keep getting better, so improving service. And that meant doing research on a lot of different things, physical devices like the transistor or fiber optical cables or microwave systems, all of these things the labs worked on. And it was kind of just the beginning of real boom times in computing as well.
Lex Fridman 13:57 Yeah.
Brian Kernighan 13:57 'Cause when I was there, I went there first in '66, so computing was at that point fairly young, and so people were discovering that you could do lots of things with computers.
Lex Fridman 14:08 So how was UNIX born?
Brian Kernighan 14:10 So Multics, in spite of having an enormous number of really good ideas and lots of good people working on it, fundamentally didn't live up, at least in the short run on it, I think ultimately really ever, to the, its goal of being this information utility. It was too expensive and certainly what was promised was delivered much too late. Um, and so in roughly the beginning of 1969, Bell Labs pulled out of the project. The project at that point had included MIT, Bell Labs, and General Electric. General Electric made computers, so General Electric was the hardware operation. So Bell Labs, realizing this wasn't going anywhere on a time scale they cared about, um, pulled out of the project. And this left several people w- with an acquired taste for really, really nice computing environments, but no computing environment. And so they started thinking about what could you do if you're on a design, a new operating system that would provide the same kind of comfortable computing as CTSS had, but also the facilities of something like Multics sort of brought forward. Um, and so they did a lot of paper design stuff, and at the same time, Ken Thompson found what is characterized as a little used PDP-7, where he started to do experiments with file systems, just how you store information on a computer in an efficient way.
Lex Fridman 15:35 (laughs)
Brian Kernighan 15:35 And then this famous story that his wife went away to California for three weeks taking their one-year-old son, and three weeks, and he sat down and wrote an operating system, which ultimately became UNIX. So software productivity was good in those days.
Lex Fridman 15:49 (laughs) So PDP, what's a PDP-7? So it's a piece of hardware?
Brian Kernighan 15:53 Yeah, it's a piece of hardware. It was one of, uh, early machines made by Digital Equipment Corporation, DEC, um, and it was a mini computer, so-called. It had, eh, I would have to look up the numbers exactly, but it had a very small amount of memory, maybe 16K, 16-bit words or something like that, relatively slow. Probably not super expensive. Maybe, again, making this up, I'd have to look it up, $100,000 or something like that.
Lex Fridman 16:21 Which is not super expensive in those days, right?
Brian Kernighan 16:24 It was expensive. It was enough that you and I probably wouldn't be able-
Lex Fridman 16:27 Right.
Brian Kernighan 16:27 ... to buy one, but a modest group of people could get together. But in any case, in, it came out, if I recall, in 1964, so by 1969, it was getting a little obsolete, and that's why it was little used.
Lex Fridman 16:41 If you can sort of comment, what do you think it's like to write an operating system like that? So that process that Ken went through in three weeks, uh, because you were... I mean, you were part of that process. You contributed a lot to, uh, to UNIX's early development. So what do you think it takes to do that first step, that first kind of, from design to reality on the PDP?
Brian Kernighan 17:05 Well, eh, l- let me correct one thing. I had nothing to do with it.
Lex Fridman 17:08 Oh.
Brian Kernighan 17:09 So I did not write it. I have never written operating system code.
Lex Fridman 17:12 Yeah.
Brian Kernighan 17:12 Um, and so I don't know. Now, an operating system is simply code, and this first one wasn't very big, but it's something that lets you run processes of some... lets you execute some kind of code-
Lex Fridman 17:26 Mm-hmm.
Brian Kernighan 17:26 ... that has been written. It lets you store information for periods of time so that it doesn't go away when you turn the power off or reboot or something like that. Um, and there's a, kind of a core set of tools that are technically not part of an operating system, but you probably need them. In this case, Ken wrote an assembler for the PDP-7 that worked. He did a text editor so that he could actually create text. He had the file system stuff that he had been working on, and then the rest of it was just a way to load things, executable code from the file system into the memory, give it control, and then recover control when it was finished or in some other way quit.
Lex Fridman 18:04 What was the code written in, the, primarily the programming language? Was it an assembly or-
Brian Kernighan 18:09 Yeah, PDP-7 old assembler that Ken created.These things were assembly language until probably the, call it, 1973 or '74, something like that.
Lex Fridman 18:20 Uh, uh, forgive me if it's a dumb question, but it feels like a daunting task to write any kind of complex system in, in assembly. Uh-
Brian Kernighan 18:28 Absolutely. (laughs)
Lex Fridman 18:30 Like, that's, it feels like impossible to do any kind of what we think of as software engineering with assembly, is, is, uh, to, to work on a big picture, sort of...
Brian Kernighan 18:40 I think it's hard. I, it's been a long time since I wrote assembly language. It, it is absolutely true that assembly language, if you make a mistake, nobody tells you. There are no training wheels whatsoever. Um, and so stuff doesn't work. Now what? And you're-
Lex Fridman 18:52 There's no debuggers?
Brian Kernighan 18:53 Well, there could be debuggers, but that, that re-, that's the same problem, right? How do you actually, um, get something that will help you debug it? So part of it is, is, um, an ability to see the big picture. Now these systems were not big in the sense that today's pictures are. So the big picture was, in some sense, more manageable. I mean, then realistically, there's an enormous variation in the capabilities of programmers, and Ken Thompson who did that first one is, is kind of the singularity, uh, in my experience of programmers. Uh, with no disrespect to you or even to me, he's-
Lex Fridman 19:28 (laughs) No, I-
Brian Kernighan 19:29 ... he's in a several leagues removed... (laughs)
Lex Fridman 19:31 I know there's levels. There's, it's, it's a, it's a fascinating thing that there are unique stars, in particular in the programming space, and at a particular time, you know? The time matters too, the timing of when that person comes along.
Brian Kernighan 19:43 Yeah.
Lex Fridman 19:44 And the, uh, a wife does have to leave to k-, like, there's this weird timing that happens that, and then all of a sudden, something beautiful is created. I mean, how does it make you feel that there's a system that was created in, in three weeks, or maybe you could even say on a whim, but not really, but of course, quickly, that is now, you could think of most of the computers in the world run on a Unix-like system.
Brian Kernighan 20:10 Right.
Lex Fridman 20:11 (laughs) What, what, how do you inter-, like, uh, if you kinda zoom from the alien perspective, if you're just observing Earth, then all of a sudden, these computers took over the world, and they started from this little initial seed of, uh, Unix. How does that make you feel? (laughs)
Brian Kernighan 20:26 It's quite surprising, and, and, and you asked earlier about prediction. The answer's-
Lex Fridman 20:30 Yeah.
Brian Kernighan 20:30 ... no. There's no way you could predict that kind of evolution, and I don't know whether it was inevitable or just a whole sequence of blind luck. I suspect-
Lex Fridman 20:39 Yeah.
Brian Kernighan 20:39 ... more of the latter. And, um, so I look at it and think, "Gee, that's kind of neat." (laughs)
Lex Fridman 20:45 (laughs)
Brian Kernighan 20:47 Uh, what, I think the real question is what does Ken think about that? 'Cause he's the guy arguably from whom it really came, you know, tremendous contributions from Dennis Ritchie and then others around in that Bell Labs environment, but, you know, if you had to pick a single person, that would be Ken.
Lex Fridman 21:04 So you've, uh, written in your book, Unix: A History and a Memoir. Are there some memorable human stories, funny or profound from that time that just kinda stand out?
Brian Kernighan 21:14 Oh, there's a lot of them in a sense, and again, it's a question of can you resurrect them, um, in real time way? (laughs)
Lex Fridman 21:19 Remember? (laughs)
Brian Kernighan 21:19 (laughs) As memory fails. Uh, but I think, uh, part of it was that Bell Labs at the time was, was a very special kind of place to work because there were a lot of interesting people and the environment was very, very open and free. It was a very cooperative environment, very friendly environment. And so if you had an interesting problem, you go and talk to somebody, and they might help you with the solution, and, um, and, and it was kind of a fun environment too in which people did strange things and, um, often tweaking the bureaucracy in one way or another.
Lex Fridman 21:52 So rebellious in pa-, uh, in certain kinds of ways?
Brian Kernighan 21:54 Uh, uh, in some ways, yeah, absolutely. I think most people didn't take too kindly to the bureaucracy, and I'm sure the bureaucracy put up with an enormous- (laughs)
Lex Fridman 22:03 (laughs)
Brian Kernighan 22:03 ... amount that they didn't really want to.
Lex Fridman 22:06 So maybe to linger on it a little bit,
Unix philosophy
Lex Fridman 22:09 do you have a sense of what the philosophy that characterizes Unix's, the design, not just the initial, but just carry through the years, just b- being there, being around it, what's the fundamental philosophy behind the system?
Brian Kernighan 22:23 I think one aspect of the fundamental philosophy was to provide an environment that made it easy to write or easier, productive to write programs. So it was meant as a programmer environment. It wasn't meant specifically as something to do some other kind of job. For example, it was used extensively for word processing, but it wasn't designed as a word processing system. It was used extensively for lab control, but it wasn't designed for that. It was used extensively as a front end for big other systems, big dumb systems, but it wasn't designed for that. It was meant to be an environment where it was really easy to write programs. And so the programmers could be highly productive. And part of that was to be a community, and there's some observation from Dennis Ritchie I, I think at the end of the book that says that in, that from his standpoint, the real goal was to, uh, create a community where people could work, uh, as programmers on the system. And I think in that sense, certainly for many, many years, it succeeded quite well at that. And part of that is the technical aspects of because it made it really easy to write programs, people did write interesting programs, and those programs tended to be used by other programmers, and so it was kind of a virtuous circle, uh, of more and more stuff coming out that was really good for programmers.
Lex Fridman 23:39 And you're part of that community of programmers. So what was it like writing programs in that early Unix?
Brian Kernighan 23:45 It was a blast. It really was. (laughs) You know, I like to program. I'm not a terribly good programmer, but it was a lot of fun to write code, and in the early days, there was an enormous amount of what you would today, I suppose, call low-hanging fruit. People hadn't done things before, and this was this new environment, and the, the whole combination of nice tools and very responsive system and tremendous colleagues made it possible to write code. You could, you could have an idea in the morning. You could do a, a, you know, an experiment with it. You could have something limping along that night or the next day, and people would react to it, and they would say, "Oh, that's wonderful, but you really screwed up here."... and, and the feedback loop was then very, very short and tight. And so a lot of things got developed fairly quickly that, um, in many cases still exist today, and I think that was part of what made it fun. Because programming itself is fun, it's puzzle-solving in a variety of ways. But I think it's even more fun when you do something that somebody else then uses, even if they whine about it not working, the fact that they used it is, is part of the reward mechanism.
Lex Fridman 24:58 And what was the method of in- interaction, the communication when you, that feedback loop? I mean, this is before the internet.
Brian Kernighan 25:05 Certainly before the internet. Um, it was mostly physical right there, you know, somebody would come into your office and say something, um-
Lex Fridman 25:13 So these places are all close by, like offices-
Brian Kernighan 25:16 Oh, yeah.
Lex Fridman 25:16 ... or nearby, so you-
Brian Kernighan 25:17 Oh, yeah.
Lex Fridman 25:17 ... had really lively inter- interaction?
Brian Kernighan 25:19 Yeah, yeah. No, Bell Labs was fundamentally one giant building, and most of the people were involved in this Unix stuff were in two or three corridors, and there was a room... Oh, how big was it? Probably, call it 50 feet by 50 feet. Make up a number of that, which had some access to computers there as well as in offices, and people hung out there and it had a coffee machine. And so th- there was a, it was mostly very physical. We did use email, of course, um, and, but it was fundamentally all, for a long time, all on one machine, so there was no need for internet.
Lex Fridman 25:56 It's fascinating to think about what computing would be today without Bell Labs, 'cause it seems so many... The people being in the vicinity of each other, the sort of getting that quick feedback, working together, so, so many brilliant people. It, I don't know where else that could've existed in the world, um, given how that came together. What... (laughs) Yeah, wh- how does that make you feel that that's, that little element of history?
Brian Kernighan 26:23 Well, I think that's very nice, but i- in a sense it's survivor bias, and if-
Lex Fridman 26:27 (laughs) Right.
Brian Kernighan 26:27 ... it hadn't happened at Bell Labs, there were other places that were doing really interesting work as well. Xerox PARC is perhaps the most-
Lex Fridman 26:34 That's right. Yeah.
Brian Kernighan 26:34 ... obvious one. Xerox PARC contributed an enormous amount of good material, um, and many of the things we take for granted today in the same way came from Xerox PARC experience. I don't think they capitalized in the long run as much. Their parent company was perhaps not as lucky in capitalizing on this. Who knows? But that would, that's certainly another place where there was a tremendous amount of, uh, influence. There were a lot of good university activities. MIT was (laughs) obviously no slouch in this kind of thing-
Lex Fridman 27:03 Yeah.
Brian Kernighan 27:04 ... and, and others as well. Um...
Lex Fridman 27:07 So Unix turned out to be open source because of the various ways that AT&T operated and sort of it had to, um, it was, the focus was on telephones. So w-
Brian Kernighan 27:19 I think that's a mischaracterization in a sense. It absolutely was not open source. It was-
Lex Fridman 27:24 Mm-hmm.
Brian Kernighan 27:24 ... very definitely proprietary, licensed, but it was licensed freely to universities in source code-
Lex Fridman 27:31 Ah.
Brian Kernighan 27:31 ... form for many years. And because of that, generations of university students and their faculty people, uh, grew up knowing about, uh, Unix, and there was enough expertise in the community that it then became possible for people to kind of go off in their own direction and build something that looked Unix-like. Um, the Berkeley version of Unix started with that licensed code and gradually picked up enough of its own, uh, code contributions, notably from people like Bill Joy, that, uh, eventually it was able to become completely free of any T- AT&T code. Now, there was an enormous amount of legal jockeying around this that, in the late, early to late '80s, early '90s, something like that. Um, and then, um, not... Some, the, I guess the open source movement might have started when Richard Stallman started to think about this in the late '80s, and by 1991 when Torvalds decided he was going to do a Unix-like operating system, there was enough expertise that, uh, in the community that first he had a target. He could see what to do because the S- the, kind of the Unix system call interface and the tools and so on were there, um, and so he was able to build a, an operating system that, at this point, when you say Unix, m- in many cases what you're really thinking is Linux.
Lex Fridman 28:58 Linux, yeah. But it's, it's funny that from my distant perception, I felt that Unix was open source without actually knowing it, but what y- you're really saying it was just, uh, freely licensed. So-
Brian Kernighan 29:11 It was freely licensed, yeah.
Lex Fridman 29:13 So it felt open source in a se- because universities are not trying to make money so they're, it felt open source in a sense that you can get access if you wanted.
Brian Kernighan 29:20 Right, and, and, and a very, very, very large number of universities had the license and they were able to talk to all the other universities who had the license, and so technically not open, technically belonging to AT&T, pragmatically pretty open.
Lex Fridman 29:34 And so there's a ripple effect that all the faculty and the students, then they all grew up and then, uh, they're, they're went throughout the world and, uh, permeated in that kind of way. So what, um, kind of features do you think make for a good operating system if you take the lessons of, uh, Unix? You said, ex- you know, make it easy for programmers, like, tha- that seems to be, uh, an important one. But also Unix turned out to be exceptionally robust and efficient.
Brian Kernighan 30:08 Right.
Lex Fridman 30:08 So, uh, is that an accident when you focus on the programmer or is that a natural outcome?
Brian Kernighan 30:14 I think part of the reason for efficiency was that it began on extremely modest hardware, very, very, very tiny, and so you couldn't get carried away, you couldn't do a lot of complicated things-... because you just didn't have the resources, either processor speed or memory, and so that enforced a certain, uh, minimality of mechanisms, and maybe a search for generalizations so that you would find one mechanism that served for a lot of different things rather than having lots of different special cases. I think the file system, uh, in Unix is a good example of that. The file system interface in its fundamental form is extremely straightforward, and that means that you can write code, um, very, very effectively for the file system. And then one of those idea, one of those generalizations is that, gee, that file system interface works for all kinds of other things as well, and so in particular, the idea of reading and writing to devices is the same as reading and writing to a disc that has a file system. And then that gets carried further in other parts of the world. Processes become, in effect, files in a file system, um, and the Plan 9 operating system which came along I guess in the late '80s or something like that, uh, took a lot of those ideas from the original Unix and tried to push the generalization even further so that in Plan 9 a lot of different resources are file systems, they all share that interface. So that would be one example-
Lex Fridman 31:41 Mm-hmm.
Brian Kernighan 31:42 ... uh, where finding the right model of how to do something means that an awful lot of things become simpler, and it means therefore that more people can do useful, interesting things with them without having to think as hard about it.
Is programming art or science?
Lex Fridman 31:54 So you said you're not a very good programmer. (laughs)
Brian Kernighan 31:57 Uh, true.
Lex Fridman 31:58 You're, you're the world's most modest human being, okay, but you'll continue saying that. I understand how this works. But you do radiate a sort of love for programming, so let me ask, uh, do you think programming's more an art or a science? Is it creativity or kind of rigor?
Brian Kernighan 32:16 I think it's some of each and it's some combination. Um, some of the art is figuring out what it is that you really want to do, what should that program be, what, what would make a good program, and that's s- some understanding of what the, the task is, what the people who might use this program want, and I think that's, that's art, uh, in many respects. The science part is trying to figure out how to do it well, and some of that is, uh, real computer science-y stuff like what algorithm should we use at some point, mostly in the sense of being careful to use algorithms that will actually work properly, scale properly, avoiding quadratic algorithms when a linear algorithm should be the right thing, that kind of more formal view of it. Um, same thing for data structures. But also it's, I think, an engineering field as well, and engineering's not quite the same as science because engineering you're working with constraints. You have to, um, figure out not only to what is a good algorithm for this kind of thing, but what's the most appropriate algorithm given the amount of time we have to compute, the amount of time we have to program, what's likely to happen in the future with maintenance, who's gonna pick this up in the future, all of those kind of things that if you're an engineer you get to worry about, whereas if you think of yourself as a scientist, well, you can maybe push them over the horizon in a way. And if you're an artist, what's that?
Lex Fridman 33:44 (laughs) So just on your own personal level, what's your process like of writing a program, say, a small and large sort of tinkering with stuff, uh, do you just start coding right away and just kind of evolve iteratively with a loose notion or do you plan on a sheet of paper first and then kind of design in a, in a what they teach you in the kind of, uh, software engineering courses in undergrad or something like that? What's your process like?
Brian Kernighan 34:14 Uh, it's certainly much more the informal incremental first. I don't write big programs at this point. Uh, it's been a long time since I wrote a program that was more than, I call it a few hundred or more lines, something like that. Many of the programs I write are experiments for, uh, either something I'm curious about or often for something that I want to talk about in a class, and so those necessarily tend to be relatively small. Um, a lot of the kind of code I write these days tends to be for sort of exploratory data analysis where I've got some collection of data and I want to try and figure out what on earth is going on in it, and for that those programs tend to be very small. Sometimes you're not even programming, you're just using existing tools like counting things, or sometimes you're writing AWK scripts because two or three lines will tell you something about a piece of data and then when it gets bigger, well, then I will probably write something in Python, um, because that scales better up to, call it a few hundred lines or something like that. And it's been a long time since I wrote programs that were much more than that.
AWK
Lex Fridman 35:18 Speaking of data exploration and AWK, uh, first, what is AWK?
Brian Kernighan 35:23 So AWK is a scripting language that was done, um, by myself, Al Aho, and Peter Weinberger. Uh, we did that originally in the late '70s. It was a language that was meant to make it really easy to do quick and dirty, uh, tasks like counting things or selecting interesting, uh, information from basically all text files, rearranging it in some way or summarizing it.
Lex Fridman 35:48 It runs a command on each line of a file. I mean, there's, um, it's still exceptionally widely used today.
Brian Kernighan 35:55 Oh, absolutely, yeah, it's, it's-
Lex Fridman 35:56 And it's so simple and elegant, sort of the way to explore data turns out you can just write a script that does something seemingly trivial on a single line and that, uh, giving you that slice of the data somehow reveals something fundamental about the data.
Brian Kernighan 36:13 Yeah.
Lex Fridman 36:13 And that keeps... (laughs) that, that seems to work still.
Brian Kernighan 36:17 Yeah, it's, it's, uh, very good for that kind of thing, you know, which, uh, that's sort of what it was meant for. I think what we didn't appreciate was that the model was actually quite good for, uh, a lot of data processing kinds of tasks, and that it's, it's kept going as long as it has, 'cause at this point it's over 40 years old and it's still-... I think a useful tool and it, well, this is paternal interest, I guess, but I think in terms of programming languages, you get the most bang for the buck by learning AWK. And it doesn't scale the big programs, but it does pretty, pretty darn well on these little things where you just want to see all the somethings in something. And so, yeah, I find, I probably write more AWK than anything else at this point. (laughs)
Lex Fridman 36:58 (laughs) Uh, so what, what kind of stuff do you love about AWK? Like is there... He- if you can comment on sort of things, uh, that give you joy when you can in, in a simple program reveal something about the data. Is there something that stands out, some particular features?
Brian Kernighan 37:14 I think it's mostly the, the selection, the, of default behaviors, that you sort of hinted at it a moment ago. What AWK does is to read through a set of files and then within each file, it reads through a- each of the lines, and then on each of the lines, it has a set of patterns that it looks for, that's your AWK program. And if one of the patterns matches, there is a corresponding action that you might perform. And so it's kind of a quadruply nested loop or something like that.
Lex Fridman 37:44 (laughs)
Brian Kernighan 37:45 Um, and that's all completely automatic. You don't have to say anything about it, you just write the pattern and the action and then run the data by it. And, and so that paradigm for programming is very natural and effective one. And I think we captured that reasonably well in AWK. And it does other things for free as well. It splits the data into fields, so that on each line there is fields separated by white space or something. And so it does that for free, you don't have to say anything about it. Um, and it collects information as it goes along, like what line are we on, how many fields are there on this line. So, lots of things that just make it so that a program which in another language, let's say Python, would be five, 10, 20 lines, in AWK it's one or two lines.
Lex Fridman 38:28 And so because it's one or two lines, you can do it on the shell, like you don't have to open up another whole thing, you can just do it right there in the interaction with the, with the operating system-
Brian Kernighan 38:37 Yeah. Just type. Yeah.
Lex Fridman 38:37 ... directly. Is there other shell commands that you love over the years, like you really enjoy using?
Brian Kernighan 38:46 Oh, grep.
Lex Fridman 38:46 I mean, just gre- (laughs)
Brian Kernighan 38:47 Grep's the only one. (laughs)
Lex Fridman 38:49 (laughs)
Brian Kernighan 38:49 Yeah, grep does everything. Uh-
Lex Fridman 38:51 So grep is a kind of a, what is it? A simpler version of AWK I would say?
Brian Kernighan 38:55 In, in some, um, some sense yeah, right, because-
Lex Fridman 38:58 What is grep?
Brian Kernighan 38:58 So grep is, it basically searches the input for particular patterns, regular expressions technically of a certain class. Um, and it has that same paradigm that AWK does, it's a pattern action thing, it reads through all the files and then all the lines in each file, but it has a single pattern which is the regular expression you're looking for, and a single action printed if it matches. So it's a, in that sense it's a much simpler version and you could write grep in AWK as, as a one-liner. Um, and I use grep probably more than anything else at this point, uh, just because it, it's so convenient and natural.
Lex Fridman 39:35 Why do you think it's such a powerful tool, grep and AWK, why do you think operating systems like Windows, for example, don't have it? Sort of you can of course, I use the, the, which is amazing now, there's, uh, Windows for Linux, so, uh, like the, which you could basically use all the fun stuff like AWK and grep in- inside of Windows. But Windows naturally sort of in the, as part of the graphical interface, the simplicity of grep, sort of searching through a bunch of files and just popping up naturally. What, why don't you think that, why do you think that's unique to the Unix and, uh, Linux environment?
Brian Kernighan 40:11 I don't know and it's not strictly unique but it's certainly focused there and I think some of it's the weight of history, um, that Windows came from MS-DOS. MS-DOS was a pretty pathetic operating system, although common on an, you know, unboundedly large number of machines. But somewhere in roughly the '90s, uh, Windows became a graphical system and I think Microsoft spent an- uh, a lot of their energy on making that graphical interface what it is. Um, and that's a different model of computing and it's a model of computing that where you point and click and sort of experiment with menus, it's a model of computing works right, rather well for people who are not programmers, who just want to get something done. Whereas teaching something like the command line to non-programmers turns out to sometimes be an uphill struggle. And so I think Microsoft probably was right in what they did. Now, you mentioned WSL or whatever it's called, the Linux, Linux-
Lex Fridman 41:09 WSL. I wonder how it's pronounced. W-S-L is what? I've never actually pronounced a WSL, I like it.
Brian Kernighan 41:14 I have no idea. (laughs)
Lex Fridman 41:15 WSL.
Brian Kernighan 41:16 But there have been things like that for a long... Cygwin, for example, which is a wonderful collection of take all your favorite tools from Unix and Linux and just make them work perfectly on Windows, and so that's a, uh, something that's been going on for at least 20 years if not longer, and I use that on my one remaining Windows machine, uh, routinely because it, it's for if you're doing something that is batch computing, command li- suitable for command line, uh, that's the right way to do it because the Windows equivalents are, if nothing else, not familiar to me.
Lex Fridman 41:47 Well, I should, I would definitely recommend to people to if they don't use Cygwin to try WSL.
Brian Kernighan 41:52 Yes. (laughs)
Lex Fridman 41:53 That's, uh, I, uh, I've been so excited that I could use Bash, WBash, write scripts quickly in, in Windows. It's changed my, my life.
Programming setup
Lex Fridman 42:03 Okay, what's your perfect programming setup? What computer, what operating system, what keyboard, what editor?
Brian Kernighan 42:10 Yeah. Perfect is too strong a word. (laughs) It's way too strong a word. Um, what I use by default, I have a, uh, at this point a 13-inch MacBook Air which I use because it's kind of a reasonable balance of the various things I need, I can carry it around, it's got enough computing horsepower, screen's big enough, keyboard's okay. Um, and so I basically do most of my computing on that. Um, I have a big iMac in my office that I use from time to time as well, especially when I need a big screen, but otherwise tends not to be used that much. Um, uh...
Lex Fridman 42:47 ... editor?
Brian Kernighan 42:48 I use mostly Sam, which is an editor that Rob Pike wrote long ago, uh, at Bell Labs, and, and-
Lex Fridman 42:55 Did that, sorry to interrupt, does that precede VI? Does that precede EMAX?
Brian Kernighan 42:59 Uh, it posts, it postdates both VI and EMAX. Um, it is derived from Rob's experience with ED and VI. Um-
Lex Fridman 43:11 What's ED?
Brian Kernighan 43:12 That's the original Unix editor. (laughs)
Lex Fridman 43:14 Oh, wow. Um-
Brian Kernighan 43:16 Dated probably before you were born. (laughs)
Lex Fridman 43:19 (laughs) So, uh, what's, uh, actually what's the history of editors? Can you, can you briefly... 'cause it's such a fac- I used EMAX, I'm sorry to say. So- sorry to come out with that. But, uh, what's, what's the kind of interplay there? So Sam and EMAX and VI?
Brian Kernighan 43:35 So, in an- so in ancient ti- ancient times, uh, like call it the first time sharing systems going back to what-
Lex Fridman 43:39 Yeah.
Brian Kernighan 43:39 ... we were talking about, there were editors, there was an editor on CTSS that I don't even remember what it was called, although it might've been edit, um, where you could type text, program text and it would do something, or doc- document text.
Lex Fridman 43:53 You could save the text?
Brian Kernighan 43:55 And save it. You could edit it, you know, the usual thing that you would get in an editor. Um, and Ken Thompson wrote an editor called QED, which, uh, was very, very powerful, but these were all totally a command based. They were not mouse or cursor based, because it was before mice and even before cursors, 'cause they were running on terminals that printed on paper.
Lex Fridman 44:16 Mm-hmm.
Brian Kernighan 44:16 Okay? No, no CRT type displays, let alone LEDs. Um, and so then when Unix came along, Ken took QED and stripped it way, way, way, way down, and that became an editor that he called ED. And it was very simple, but it was a line-oriented editor. And so you, you could load a file, and then you could talk about the lines one through the last line, and you could, um, you know, print ranges of lines. You could add text, you could delete text, you could change text, or you could do a substitute command that would change things within a line or within groups of lines.
Lex Fridman 44:49 So you could work on a parts of a file, essentially?
Brian Kernighan 44:51 Yeah, you could work on any part of it, the whole thing or whatever, but it was entirely command line based and it was-
Lex Fridman 44:57 Oh.
Brian Kernighan 44:57 ... entirely on paper.
Lex Fridman 45:00 Okay.
Brian Kernighan 45:00 Paper. And that meant that you changed-
Lex Fridman 45:02 Actual paper.
Brian Kernighan 45:03 Yeah, right, real paper. And so if you changed a line, you had to print that line using up another line of paper to see what the change caused, okay?
Lex Fridman 45:11 (laughs) Yeah. That's amazing.
Brian Kernighan 45:13 So when, when CRT displays came along-
Lex Fridman 45:16 Yeah.
Brian Kernighan 45:17 ... then, uh, you could start to use cursor control and you could sort of move where you were on the screen in, um-
Lex Fridman 45:24 Without reprinting every time. (laughs)
Brian Kernighan 45:25 Without reprinting. And one of, there were a number of editors there. The one that I was most familiar with and still use, uh, is VI, which was done by Bill Choi. And so, uh, that dates from probably the late '70s, as a guess. And, uh, it took full advantage of the cursor controls. I suspect that EMAX was roughly at the same time, but I don't know. I've never internalized EMAX. So, so I use, at this point I stopped using ED, although I still can. Um, I use VI sometimes and I use Sam when I can.
Lex Fridman 46:00 And Sam is available on most systems?
Brian Kernighan 46:02 It was, um, it is available. You have to download it yourself from typically the Plan 9 operating system distribution. It's been maintained by, uh, people there, uh, and so I-
Lex Fridman 46:12 I'll get home tonight, I'll try it. (laughs) That's cool.
Brian Kernighan 46:14 Yeah.
Lex Fridman 46:14 It sound, it, uh, sounds, sounds fascinating. Yeah, although my love is with Lisp and EMAX, I've went into that hippie world of (laughs) -
Brian Kernighan 46:24 (laughs) . I think it's a lot of things, what religion were you brought up with?
Lex Fridman 46:27 Yeah, that's true. That's true. I, most of the actual programming I do is C, C++ and Python, but my weird sort of, yeah, my religious upbringing is in Lisp. (laughs) . So,
History of programming languages
Lex Fridman 46:39 can you take on the impossible task and give a brief history of programming languages from your perspective?
Brian Kernighan 46:46 So, I guess you could say programming languages started probably in, what, the late '40s or something like that. People used to program computers by basically putting in zeros and ones, using something like switches on a console. Uh, and then, uh, or maybe holes in paper tapes, something like that. So extremely tedious, awful, whatever. And so I think the first programming languages were, uh, relatively crude assembly languages, where people would basically write a program that would convert mnemonics like add, A-D-D, into whatever the bit pattern was that corresponded to an add instruction, and they would do the clerical work of figuring out where things were, so you could put a name on a location in a program and the assembler would figure out where that corresponded to when the thing was all put together and dropped into memory. Um, and they w- m- early on, and this would be the late '40s, uh, and very early '50s, there were assemblers written for the various machines that people used. You may have seen in the paper just a couple of days ago Tony Burkard died. He did this thing in Manchester called the, called Autocode, a language which I knew only by name. Um, but it sounds like it was a flavor of assembly language, sort of a little higher in some ways. Um, and it replaced a language that Alan Turing wrote, which you put in zeros and ones, but you put them in backwards order because that was how the hardware worked. Very strange.
Lex Fridman 48:14 That's right.
Brian Kernighan 48:15 (laughs)
Lex Fridman 48:15 Yeah, yeah. That's right, it's backwards.
Brian Kernighan 48:18 So assembly languages then, let's call that the early 1950s. And so every different flavor of computer has its own assembly language. So the EDSAC had its, and the Manchester had its, and the IBM whatever, 70-90 or 704 or whatever had its, and, and so on. So everybody had their own assembly language.
Lex Fridman 48:35 And assembly languages have a few commands, addition, subtraction, and branching of some kind, if then type of situation.
Brian Kernighan 48:42 Right. They have exactly, in their simplest form at least, one instruction per, or one, uh, assembly language instruction per instruction in the machine's repertoire.
Lex Fridman 48:52 Right.
Brian Kernighan 48:52 ... and so you have to know the machine intimately to be able to write programs in it. And if you write an assembly language program for one kind of machine, and then you say, "Geez, it's nice. I'd like it in a different machine," start over.
Lex Fridman 49:03 (laughs)
Brian Kernighan 49:03 Okay.
Lex Fridman 49:04 Yeah.
Brian Kernighan 49:04 So very bad. And so what happened in the late '50s was people realized you could play this game again and you could move up a level in writing or creating languages that were closer to the way that real people might think about how to write code. Um, and there were, I guess, arguably three or four at that time period. There was Fortran, which came from IBM, which was formula translation, meant to make it easy to do scientific and engineering computations.
Lex Fridman 49:32 I didn't know that. Formula translation, that's wow.
Brian Kernighan 49:34 That's what it stood for.
Lex Fridman 49:35 Yeah.
Brian Kernighan 49:35 And there was COBOL, which is the common business-oriented language that, uh, Grace Hopper and others worked on, uh, which was aimed at business kinds of tasks. Uh, there was ALGOL, which was mostly meant to describe algorithmic computations. Um, I guess you could argue Basic was in there somewhere. I think it's just a little later. Um, and so all of those moved a level up, and so they were closer to what you and I might think of as we were trying to write a program, and they were focused on different domains. Fortran for formula translation, engineering computations, let's say, COBOL for business, that kind of thing.
Lex Fridman 50:11 Mm. Still used today, at least Fortran-
Brian Kernighan 50:13 Still used today.
Lex Fridman 50:14 ... probably.
Brian Kernighan 50:14 Oh, yeah. COBOL too.
Lex Fridman 50:16 COBOL.
Brian Kernighan 50:16 But the deal was that once you moved up that level, then you... let's call it Fortran, you had a language that was not tied to a particular kind of hardware because a different compiler would compile for a different kinda hardware, and that meant two things. It meant you only had to write the program once, which was very important, and it meant that you could in fact, if you were a random engineer, physicist, whatever, you could write that program yourself. You didn't have to hire a programmer to do it for you. Might not be as good as you'd get with a real programmer, but it was pretty good, and so it democratized and made much more broadly available the ability to write code.
Lex Fridman 50:51 So it puts the power of programming into the hands of people like you?
Brian Kernighan 50:54 Yeah. Anybody who wants t- who u- who under- is willing to invest some time in learning a programming language and is not then tied to a particular kind of computer, and then in the '70s you get system programming languages of which C is the survivor, and-
Lex Fridman 51:09 What, what, what does system programming languages mean?
Brian Kernighan 51:11 Lang- programs that... Programming languages that would take on the kinds of things that were necessary to write so-called system programs, things like text editors or assemblers or compilers or operating systems themselves, those kinds of things. And s- uh, Fortran-
Lex Fridman 51:28 They have to be feature-rich. They have to be able to do a lot of stuff, a lot of memory management, uh, the access processes, all that kind of stuff-
Brian Kernighan 51:34 They have to-
Lex Fridman 51:35 ... parallel processing.
Brian Kernighan 51:35 It's a different flavor of what they're doing. They're much more i- in touch with the actual machine in a... but in a positive way, that is, you can talk about memory in a more controlled way, um, you can talk about the different data types that the machine supports and the way they're, um... and more ways to structure and organize data. And so the system programming languages, there was a lot of effort in that, in the, call it the late '60s, early '70s. C is, I think, the only real survivor of that, um, and then what happens after that, uh, you get things like object-oriented programming languages because as you write programs in a language like C, at some point scale gets to you and it's too hard to keep track of the pieces and there's no guardrails or training wheels or something like that to prevent you from doing bad things, um, so C++ comes out of that tradition, and so-
Lex Fridman 52:28 And then it took off from there. I mean, there's also a parallel, slightly parallel track with a little bit of the functional stuff, with Lisp and so on, but I guess from that point, it's just an explosion of languages.
Brian Kernighan 52:38 Yeah.
Lex Fridman 52:38 There's the Java story, there's the JavaScript, there's all the stuff that the cool kids these days are doing with Rust and all that.
Brian Kernighan 52:47 Yeah.
C programming language
Lex Fridman 52:48 So what's, to you... so you wrote a book, The C Programming Language, what... and C is probably one of the most important languages in the history of programming languages if, if you kind of look at impact. W- what do you think is the most elegant or powerful part of C? Why did it survive? Why did it have such a long-lasting impact?
Brian Kernighan 53:11 I think it found a sweet spot that... in... of expressiveness, that you could rewrite things in a pretty natural way, and efficiency, which was particularly important when computers were not nearly as powerful as they are today, you know, put yourself back 50 years, uh, almost in terms of what computers could do and that's, you know, roughly four or five generations, uh, decades of Moore's Law, right? Um, so expressiveness and efficiency and, I don't know, perhaps the environment that it came with as well, which was Unix, so that meant if you wrote a program, it could be used on all those computers that ran Unix and that was all of those computers because they were all written in C and that way it was Unix the operating system itself was portable as were all the tools. So it all worked together, a- again, in one of these things where things fed on each other in a positive cycle.
Lex Fridman 54:06 What did it take to write sort of a definitive book, probably a definitive book on all of programming, like, it's more definitive to a particular language than any other book on any other language, and did two really powerful things which is popularized the language, at least from my perspective, maybe you can correct me, and second is created a standard of how, you know, the, the, how this language is supposed to be used and applied. So what did it take? Did you have those kinds of ambitions in mind when working on that?
Brian Kernighan 54:38 Is this some kind of joke?
Lex Fridman 54:40 (laughs)
Brian Kernighan 54:40 (laughs) No, of course not. Um... (clears throat)
Lex Fridman 54:42 So it's an acc- it's an accident of, uh, of timing, skill, and just luck?
Brian Kernighan 54:48 A lot of it is, uh, uh, clearly. Uh, timing was good. Uh, Dennis and I wrote the book in 1977, uh-
Lex Fridman 54:54 Dennis Ritchie.
Brian Kernighan 54:54 Yeah, right. Um, and at that point, Unix was starting to spread. I don't know how many there were but it would be dozens to hundreds of Unix systems, um, and C was also available on other kinds of computers that had nothing to do with Unix, and so the language had some potential. Um-And there were no other books on C, uh, and Bell Labs was really the only source for it, and Dennis, of course, was authoritative because it was his language, and he had written the, uh, reference manual, which is a marvelous example of how to write a reference manual. Really, really very, very well done. So I twisted his arm until he agreed to write a book, and then we wrote a book. And the virtue or advantage at least, I guess, of going first is that then, uh, other people have to follow you if they're gonna do anything. (laughs) Um, and I think it worked well because Dennis was a superb writer. I mean, he really, really did, and the, the reference manual in that book is his, period. I had nothing to do with that at all. Um, so just crystal clear prose and very, very well expressed. Um, and then he and I... I, I wrote most of the expository material, and then he and I sort of did the usual ping-ponging back and forth, um, you know, refining it. But I spent a lot of time trying to find examples that would sort of hang together and that would tell people what they might need to know at about the right time that they should be thinking about needing it. Um, and I'm not sure it completely succeeded, but it mostly worked out fairly well.
Lex Fridman 56:28 What do you think is the power of example? I mean, you're, you're the creator, uh, at least one of the first people to do the Hello World program-
Brian Kernighan 56:38 (laughs)
Lex Fridman 56:38 ... (laughs) which is like the example. If, if aliens discover our civilization hundreds of years from now, it'll probably be-
Brian Kernighan 56:44 (laughs)
Lex Fridman 56:45 ... Hello World programs, just like a, a half-broken robot communicating with them with a Hello World. So what... And that's a representative example, so what, what do you find powerful about examples?
Brian Kernighan 56:56 Uh, I think a good example will tell you how to do something, and it will be representative of, of you might not want to do exactly that, but you will want to do something that's at least in that same general vein. Um, and so a lot of the examples in the C book were picked for these very, very simple, straightforward text processing problems that were typical of Unix. I want to read input and write it out again. There's a copy command. I wanna read input and do something to it and write it out again. There's a grab. And so that kind of find things that are representative of what people want to do and spell those out so that they can then take those and see the, the core parts and modify them to their taste. And I think that a lot of programming books that I... I, I don't look at programming books a tremendous amount these days, but when I do, a lot of them don't do that. They don't give you examples that are both realistic and something you might want to do. Some of them are pure syntax. Here's how you add three numbers. Well, come on, I could figure that out. Tell me how I would get those three numbers into the computer and how I would do something useful with them and then how I put them back out again, neatly formatted.
Lex Fridman 58:15 And especially if you follow that example, there is something magical of doing something that feels useful.
Brian Kernighan 58:21 Yeah, right? And I think it's the attempt, and it, it's absolutely not perfect, uh, but the attempt in all cases was to get something that was going to be either directly useful or would be very representative of useful things that a programmer might want to do. But within that vein of fundamentally text processing, reading text, doing something, writing text.
Go language
Lex Fridman 58:44 So you've also written a book on, uh, Go language. Uh, I'd have to admit, so I worked at Google for a while, and I've never used Go.
Brian Kernighan 58:53 Well, you missed something. (laughs)
Lex Fridman 58:54 Oh, I know I missed something, for sure. I mean, and so Go and Rust are two languages that I hear very, uh, spoken very highly of, and I wish... I would like to try. Well, there's a lot of them. There's Julia, there's, there's all these incredible-
Brian Kernighan 59:09 (laughs)
Lex Fridman 59:09 ... modern languages. But i- if you can comment, before... Or maybe comment on what do you find... Where does Go sit in, in this broad spectrum of languages, and also how do you yourself feel about this wide range of powerful, interesting languages that you might never even get to try to explore-
Brian Kernighan 59:30 Yeah.
Lex Fridman 59:30 ... just because of time?
Brian Kernighan 59:31 So I, I think... So Go, um... Go first comes from that same Bell Labs tradition in part, not exclusively, but two of the three creators, Ken Thompson and Rob Pike-
Lex Fridman 59:42 Oh, so literally the people-
Brian Kernighan 59:44 Yeah, the people.
Lex Fridman 59:45 Yeah.
Brian Kernighan 59:45 Um, and then with this very, very useful, uh, influence from the European school, uh, in particular, uh, the Claus Firth influence, uh, through Robert Griesemer, um, who was, I guess, a second generation down student r- uh, at ETH. Um, and so that's an interesting combination of things. And so some ways, uh, Go captures the good parts of C. It looks sort of like C, it's sometimes characterized as C for the 21st century.
Lex Fridman 1:00:12 Mm-hmm.
Brian Kernighan 1:00:13 Um, on the surface, it looks very, very much like C, but at the same time, it has some interesting, uh, data structuring capabilities, and then I think the part that I would say is particularly useful, and again, I'm not a Go expert, um, in spite of co-authoring the book. About 90% of the work was done by Alan Donovan, my co-author, who is a Go expert. Um, but Go provides a very nice model of concurrency. It's basically the cooperating, uh, communicating sequential processes that Tony Hoare-
Lex Fridman 1:00:48 (laughs)
Brian Kernighan 1:00:48 ... uh, set forth, geez, I don't know, 40-plus years ago.
Lex Fridman 1:00:51 (laughs)
Brian Kernighan 1:00:52 Um, and Go routines are, to my mind, a very natural way to talk about, um, parallel computation, and in the few experiments I've done with them, they're easy to write, and typically it's gonna work and very efficient as well. So I think that's one place where Go stands out at that model of, of parallel computation, uh, is very, very easy and nice.... to, to work with.
Lex Fridman 1:01:16 J- just to comment on that, do you think C foresaw, or the early Unixes foresaw, uh, threads and massively parallel computation?
Brian Kernighan 1:01:25 I would guess not really. I mean, maybe it was seen, but not at the level where it was something you had to do anything about. Um, for a long time, processors got faster, and then processors stopped getting faster because of things like power consumption and heat generation. And so what happened instead was that instead of processors getting faster, there started to be more of them. And that's where that parallel thread stuff comes in.
Lex Fridman 1:01:56 (laughs)
Learning new programming languages
Lex Fridman 1:01:57 So if you can comment on the, all the other languages-
Brian Kernighan 1:02:01 (laughs)
Lex Fridman 1:02:01 ... does it, uh, break your heart that you'll never get to explore them? Or s- how do you feel about all-
Brian Kernighan 1:02:06 Uh-
Lex Fridman 1:02:06 ... the full variety?
Brian Kernighan 1:02:07 It, it's not breaking my heart, but it, but it, I would love to be able to try more of these languages. The closest I've come is in a class that I often teach in the spring here, um, it's a programming class-
Lex Fridman 1:02:18 Mm-hmm.
Brian Kernighan 1:02:18 ... uh, and I often give... I, I have one sort of small example that I will write in as many languages as I possibly can. I've got it in 20-odd languages at this point. And, um, and that's... So I do a minimal experiment with a language just to say, "Okay, I have this trivial task, which I understand the task, and it should... it takes 15 lines in AWK and not much more in a variety of other languages. So how big is it? How fast does it run? And what pain did I go through to learn how to do it?" Um, and that's a... f- it's like anecdata, right? It's very, very, very narrowly focused.
Lex Fridman 1:02:57 Anecdata (laughs) , I like that term. So yeah, but still, it's a little sample 'cause you get to... I think the hardest step of the programming language is probably the first step, right?
Brian Kernighan 1:03:06 Yeah.
Lex Fridman 1:03:06 So there you're taking the first step.
Brian Kernighan 1:03:08 Yeah. And so my experience, um, with some languages is very positive. Like Lua, a scripting language I had n- never used, um, and I took my pro- little program... The program is a, a trivial formatter. It just takes in lines of text of, of varying lengths and it puts 'em out in lines that have no more than 60 characters on each line. So think of it as just-
Lex Fridman 1:03:29 Yeah.
Brian Kernighan 1:03:29 ... kind of the flow, uh, process in a browser or something. Um, so it's, it's very short program. And, um, in Lua, I downloaded Lua, and in an hour I had it working, never having written Lua in my life-
Lex Fridman 1:03:43 (laughs)
Brian Kernighan 1:03:43 ... just going with online documentation. I did the same thing in Scala, which you can think of as a flavor of Java, equally trivial. Um, I did it in Haskell, it took me several weeks.
Lex Fridman 1:03:53 (laughs)
Brian Kernighan 1:03:54 (laughs) But it did run like a turtle. Um, and-
Lex Fridman 1:03:59 (laughs)
Brian Kernighan 1:04:00 ... and I, I did it in Fortran 90, and it-
Lex Fridman 1:04:04 Wow.
Brian Kernighan 1:04:04 ... painful, but it worked.
Lex Fridman 1:04:06 Yeah.
Brian Kernighan 1:04:06 And I tried it in Rust, and it took me several days to get it working because the model of memory management was just a little unfamiliar to me. And the problem I had with Rust, and it's back to what we were just talking about, I couldn't find good consistent documentation on Rust. Now, this was several years ago, and I'm sure things have stabilized, but at the time, everything in the Rust world seemed to be changing rapidly. And so you would find what looked like a working example, and it wouldn't work with the version of the language that I had. So it took longer than it should have. Um, Rust is a language I would like to get back to, but probably won't. I think one of the issues, you have to have something you want to do. And if you don't have-
Lex Fridman 1:04:44 Yeah.
Brian Kernighan 1:04:45 ... something that is the right combination of, "I want to do it and yet I have enough disposable time," whatever, "to make it worth learning a new language at the same time," it's never gonna
Javascript
Brian Kernighan 1:04:57 happen.
Lex Fridman 1:04:58 So what do you think about another language of JavaScript that's... This... Uh, well, let me just sort of comment on what...
Narrator 1:05:06 (laughs)
Lex Fridman 1:05:06 Because when I was brought up, sort of JavaScript was seen as, uh, the (laughs) probably, like, the ugliest language possible.
Brian Kernighan 1:05:15 (clears throat)
Lex Fridman 1:05:15 And yet it's quite arguably, quite possibly taking over not just the front end and the back end of the internet, but possibly in the future taking over everything because they've now learned to make it very efficient.
Brian Kernighan 1:05:27 Yeah.
Lex Fridman 1:05:27 And, and so what do you think about this? (laughs)
Brian Kernighan 1:05:29 Yeah. Well, I think you captured it in a lot of ways. When it first came out, JavaScript was deemed to be fairly irregular and an ugly language. And certainly in the academy, if you said you were working on JavaScript, people would ridicule you.
Lex Fridman 1:05:40 Yeah.
Brian Kernighan 1:05:40 It was just not fit for academics to work on. Um, I think a lot of that has evolved. The language itself has evolved, and, uh, certainly the technology of compiling it is fantastically better than it was. Um, and so in that sense, it's a, a- absolutely a viable solution f- on back ends as well as the front ends. Um, used well, I think it's a pretty good language. I've written a modest amount of it, and I've played with JavaScript translators and things like that. I'm not a real expert, and it's hard to keep up even there with the new things that come along with it. Um, so I don't know whether it will ever take over the world. I think not, but, uh, it, it's certainly an important language and-
Lex Fridman 1:06:27 So-
Brian Kernighan 1:06:27 ... worth knowing more about.
Lex Fridman 1:06:29 ... there's, uh, there's... Maybe to get a, your comment on something, which JavaScript-
Brian Kernighan 1:06:33 (laughs)
Lex Fridman 1:06:33 ... and actually most languages, uh, sort of Python, such a big part of the experience of programming with those languages includes libraries. Sort of using, building on top of the code that other people have built. I think that's probably different from the experience that we just talked about from Unix and C days when you're building stuff from scratch. What do you think about this world of essentially leveraging, building up libraries on top of each other and leveraging them?
Brian Kernighan 1:06:59 Yeah. No, that's a very perceptive kind of, uh, question. One of the reasons programming was fun in the old days was that you were really building it all yourself.
Lex Fridman 1:07:09 Yeah.
Brian Kernighan 1:07:09 The, the number of libraries you had to deal with was quite small. Maybe it was printf or the standard library or something like that.Um, and that is not the case today and if you wanna do something in, you mentioned Python and JavaScript, and those are the two fine examples, you have to typically download a boatload of other stuff and you have no idea what you're getting. Absolutely nothing.
Lex Fridman 1:07:30 Yeah.
Brian Kernighan 1:07:31 I've been doing some playing with machine learning over the last couple of days and, geez, something doesn't work. Well, you PIP install this, okay? And down comes another gazillion megabytes of something and you have no idea what it was and if you're lucky, it works. And if it doesn't work? You have no recourse. There's absolutely no way you could figure out which in these thousand different packages. And I think it's worse in the MPN- NPM environment for JavaScript. I think there's less discipline, less control there.
Lex Fridman 1:08:03 And there's aspects of, uh, not just not understanding how it works but there's security issues, there's robustness issues, so you don't wanna run a nuclear power plant using JavaScript essentially.
Brian Kernighan 1:08:13 Uh, probably not. (laughs)
Lex Fridman 1:08:15 (laughs)
Variety of programming languages
Lex Fridman 1:08:16 So speaking to the variety of languages, do you think that variety is good or do you hope, think that over time we should converge towards one, two, three programming languages? That y- you mentioned to the Bell Lab days when people could sort of, the community of it, and the more languages you have, the more you separate the communities. There's the Ruby community, there's the Python community, there's C++ community. Do you hope that they, they'll unite one day to just one or two languages?
Brian Kernighan 1:08:47 I certainly don't hope it, I'm not sure that that's right 'cause I honestly don't think there is one language that will suffice for all the programming needs of the world. Are there too many at this point? Well, arguably. Um, but I think if you look at the, the sort of, the distribution of how they are used, there's (clears throat) , something, call it a dozen languages that probably account for 95% of all programming at this point.
Lex Fridman 1:09:11 Mm-hmm.
Brian Kernighan 1:09:11 And that doesn't seem unreasonable. Uh, and then there's another, well, 2,000 languages that are still in use that nobody uses and, or at least don't use in any quantity. But I think new languages are a good idea in many respects 'cause they're often a chance (clears throat) to explore an idea of how a language might help. I think that's one of the, um, positive things about functional languages. For example, they're a particularly good place where people have explored ideas that at the time (clears throat) didn't seem feasible but ultimately have wound up as part of mainstream languages as well. I mean, just go back as early as Recursion and Lisp and then follow forward, functions as first class citizens and pattern-based languages and, gee, I don't know, uh, closures and just on and on and on. Lambdas. Interesting ideas that showed up first in, let's call it broadly the functional programming community, and then find their way into mainstream languages.
Lex Fridman 1:10:13 Yeah, it's a, it's a playground for rebels.
Brian Kernighan 1:10:15 Yeah, exactly.
Lex Fridman 1:10:16 (laughs) So...
Brian Kernighan 1:10:17 And, and, and so I think the languages in the playground themselves are probably not going to be the mainstream-
Lex Fridman 1:10:24 Right.
Brian Kernighan 1:10:24 ... at least for some while, but the ideas that come from there are invaluable.
AMPL
Lex Fridman 1:10:30 So let's go to something that, wh- when I found out recently, so I- I've known that you've done a million things but one of the things I wasn't aware of that you had a role in AMPL and I... Before you interrupt me by minimizing your role in it (laughs) , would you-
Brian Kernighan 1:10:44 AMPL is for Minimizing Functions.
Lex Fridman 1:10:46 Yeah, Minimizing Functions, right, exactly (laughs) . Um, I, I, can I just say that the elegance and abstraction power of A- AMPL is incredible when I, when I first came to, to it about 10 years ago or so. Uh, can you describe what is the AMPL language?
Brian Kernighan 1:11:04 Sure. So AMPL is a language for mathematical programming, uh, technical term, uh, think of it as linear programming, that is setting up systems of linear, um, equations that are, uh, of some sort of system of constraints so that you have a bunch of things that have to be less than this, greater than that, whatever, and you're trying to find a set of values for some decision variables that will maximize or minimize some objective function. So it's, it's a way of solving a particular kind of optimization problem, a very formal sort of optimization problem, but one that's exceptionally useful.
Lex Fridman 1:11:42 Yep.
Brian Kernighan 1:11:42 Yeah.
Lex Fridman 1:11:42 And it specifies, so there's objective function constraints and variables that becomes separate from the data it operates on.
Brian Kernighan 1:11:50 Right.
Lex Fridman 1:11:50 So the, that kind of separation allows you to, uh, you know, put on different hats. One, put the hat of an optimization person and then put a, another hat of a data person and dance back and forth and, and also separate the actual, uh, solvers, the optimization systems that do the solving, that you can have other people come to the table and then build their solvers whether it's linear or nonlinear, uh, convex, non-convex, that kind of stuff. So, uh, what is the, do you use... May- maybe you can comment how you got into that world and what is a beautiful or interesting idea to you from the world of optimization?
Brian Kernighan 1:12:35 Sure. So I preface it by saying I'm absolutely not an expert on this and most of the, uh, important work in AMPL comes from my two partners in crime on that, Bob Fourer who, uh, was a professor of, in, in the Industrial Engineering and Management Science Department at Northwestern and my colleague at, uh, Bell Labs, Dave Gay who was a numerical analyst, uh, and optimization person. So the deal is linear programming (laughs) , preface this by saying... (laughs)
Lex Fridman 1:13:03 Let's stay with linear programming.
Brian Kernighan 1:13:05 Yeah, linear programming is the simplest example of this. So linear programming as it's taught in school is that you have a big matrix which is always called A and you say AX is less than or equal to B, so B is a set of constraints, X is the decision variables and A is the, how the decision vari-... pulls our combined to set up the various constraints. So A is a matrix, and X and B are vectors. Um, and then there's an objective function, which is just the sum of a bunch of Xs and some coefficients on them, and you, that's the thing you want to optimize. Um, the problem is that in the real world, that, that matrix A is a very, very, very intricate, very large, and very sparse matrix, where the various components of the model are distributed among the coefficients in a way that is totally unobvious to anybody. Um, and so what you need is some way to express the original model, which you and I would write. You know, we'd write mathematics on the board. You know, the sum of this is greater than the sum of that, kind of thing. So, um, you need a language to write those kinds of constraints. And Bob Fourer, for a long time, had been interested in modeling languages, languages that made it possible to do this. There was a, a modeling language around called GAMS, the General Algebraic Modeling System, but it looked very much like Fortran. It was kinda clunky. Um, and so Bob spent a sabbatical year at Bell Labs in 1984, and, uh, he ... And he was living in the office across from me, and, uh, it's always geography. And, uh, he and Dave Gay and I started talking about this kind of thing, and, um, he wanted to design a language that would make it so that you could take these algebraic specifications, you know, summation signs over sets, and that you would write on the board and convert them into basically this A matrix, and then pass that off to a solver, which is an entirely separate thing. And so we, uh, talked about the design of the language. I don't remember any of the details of this now, but it's kind of an obvious thing. You're just writing out mathematical expressions in a Fortran-like, or a, a, sorry, an algebraic but textual-like language. Um, and, um, I wrote the first version of this AMPL program, uh, my first C++ program.
Lex Fridman 1:15:24 (laughs)
Brian Kernighan 1:15:24 And, uh-
Lex Fridman 1:15:26 It's written in C++?
Brian Kernighan 1:15:27 Yeah.
Lex Fridman 1:15:27 AMPL. Oh, wow.
Brian Kernighan 1:15:28 And so I did that fairly quickly. We wrote ... It was w- you know, 3,000 lines or something, so it wasn't very big. But it, it sort of showed the feasibility of it, that you could actually do something that was easy for people to specify p- models and convert it into something that a solver could work with. And at the same time, as you say, the model and the data are separate things. So one model would then work with all kinds of different data in the same way that lots of programs do the same thing but with different data.
Lex Fridman 1:15:54 So one of the really nice things is the, the specification of the models, human, um, just kind of like as you say, it's human-readable. Like I, I could literally... I remember on stuff I worked, I, I would send it to colleagues that I'm pretty sure never programmed (laughs) in their life, just, just to, uh, understand what the optimization problem is.
Brian Kernighan 1:16:14 Mm-hmm.
Lex Fridman 1:16:15 I think, uh, how hard is it to convert that? You said you, there's a first prototype in C++ to convert that into something that could actually be used by the solver.
Brian Kernighan 1:16:24 It's not too bad because most of the solvers have some mechanism that lets them import a model in a form. It might be as simple as the matrix itself in just some representation, or if you're doing things that are not linear programming, then there may be some mechanism that lets you provide things like functions to be called, so, or other constraints on the model. So, uh, so all AMPL does is to generate that kind of thing, and then the solver deals with all the hard work, and then when the solver comes back with numbers, AMPL converts those back into your original form so you know how much of each thing you should be buying or making or shipping or whatever. Um, so we did that in '84, and I haven't had a lot to do with it since, except that we wrote a couple of versions of a book on it.
Lex Fridman 1:17:14 Which is one of the greatest books ever written. I love that book.
Brian Kernighan 1:17:18 (laughs)
Lex Fridman 1:17:18 Uh, I don't know why.
Brian Kernighan 1:17:20 It's an excellent book. Bob Fourer wrote most of it, and so it's really, really well done. He must have been a dynamite teacher.
Lex Fridman 1:17:25 And typeset in LaTeX.
Brian Kernighan 1:17:27 No, no, no, are you kidding? (laughs)
Lex Fridman 1:17:29 (laughs) I remember liking the typography, so I don't know-
Brian Kernighan 1:17:33 We did it with Troff.
Lex Fridman 1:17:34 I don't even know what that is.
Brian Kernighan 1:17:35 Yeah, exactly. You're too young.
Lex Fridman 1:17:36 Uh-oh. Oh, boy.
Brian Kernighan 1:17:38 Uh, think of Troff as, as a, uh, a predecessor to the TeX family of things. It's a formatter that was done at Bell Labs in this same period, in the very early '70s, uh, that predates TeX and things like that by, mm, five to 10 years.
Lex Fridman 1:17:54 But it was nevertheless ... The, just ... I'm going by memory, is, it was ... I remember it being beautiful, uh-
Brian Kernighan 1:18:00 Yeah, it was nice, the typography.
Graph theory
Lex Fridman 1:18:01 ... the typography. Outside of Unix, C, Awk, Golang, all the things we talked about, uh, all the amazing work you've done, you've also done work in graph theory. Uh, let, let me ask this, this crazy, out there question. Uh, if you had to make a bet, and I had to force you to make a bet, do you think P equals NP?
Brian Kernighan 1:18:22 (laughs) Uh, the answer is no, although I, I am told that somebody asked, uh, Jeff Dean if that was the k- under what conditions P would equal NP, and he said, "Either P is zero or N is one." (laughs)
Lex Fridman 1:18:33 (laughs)
Brian Kernighan 1:18:33 Or vice versa, I've forgotten, is what-
Lex Fridman 1:18:36 If P is zero, N is one.
Brian Kernighan 1:18:36 ... Jeff Dean is a lot smarter than I am. (laughs)
Lex Fridman 1:18:38 Yeah. (laughs) Uh, so but your intuition is, uh, a little bit on the matter of difference.
Brian Kernighan 1:18:44 I, I have no i- I have no intuition, but I've got a lot of colleagues who've got intuition, and their betting is no. (laughs)
Lex Fridman 1:18:48 That's the popular, that's the popular bet. Okay, so w- what is computational complexity theory, and do you think these kinds of complexity classes, especially as you've taught in this, this modern world, are still useful way to understand the hardness of problems?
Brian Kernighan 1:19:06 I don't do that stuff. The last time I touched anything to do with that was be-
Lex Fridman 1:19:09 Many, many years ago.
Brian Kernighan 1:19:10 ... was before it was invented.
Lex Fridman 1:19:12 (laughs)
Brian Kernighan 1:19:12 'Cause I ... (laughs) It's literally true. I did my PhD thesis on graph-
Lex Fridman 1:19:17 Before big O notation.
Brian Kernighan 1:19:18 Oh, absolutely. Before ... I, I did this in 1968, um, and I worked on graph partitioning, which is this question ... If you've got a graph, uh, that is a nodes and edges kind of graph-... and the edges have weights. And you just want to divide the nodes into two piles of equal size, so that the number of edges that goes from one side to the other is as small as possible. (inhales deeply) And...
Lex Fridman 1:19:41 We, we developed... So that problem is hard?
Brian Kernighan 1:19:45 Well, as it turns out, I worked with Shan Lin at Bell Labs on this, and we were never able to come up with anything that was guaranteed to give the right answer. We came up with heuristics that worked pretty darn well, and I peeled off some special cases for my thesis, but it was just hard.
Lex Fridman 1:20:02 Mm-hmm.
Brian Kernighan 1:20:02 And that was just about the time that Steve Cook was showing that there were classes of problems that appeared to be really hard, of which graph partitioning was one. (laughs) But this... My expertise, (laughs) such as it was, totally predates that development. Oh, it's-
Lex Fridman 1:20:16 Oh, interesting. So the, the heuristic, which now, (laughs) uh, your... Uh, cares the two of yours names for the tr- traveling salesman problem and for the graph partitioning, that was... Like, how did you... You weren't even thinking in terms of classes, you were just trying to find-
Brian Kernighan 1:20:29 There was no such idea.
Lex Fridman 1:20:31 ... a heuristic that kind of does the job pretty well.
Brian Kernighan 1:20:34 You're trying to find a, something that did the job, and there was no- nothing that you would call, let's say, a closed form or algorithmic thing that would give you a guaranteed right answer. I mean, compare graph partitioning to, uh, max flow min-cut or something like that, bec- that's the same problem, except there's no constraint on the number of nodes on one side or the other of the cut.
Lex Fridman 1:20:55 Right.
Brian Kernighan 1:20:56 And that means it's an easy problem, at least as I understand it. Whereas the constraint that says the two have to be constrained in size makes it a hard problem. (inhales deeply)
Lex Fridman 1:21:05 Yeah, so the Robert Frost has that poem where you have to choo- choose two paths. So wha- why did you... (laughs) Uh, is there another alternate universe in which you pursued the Don Knuth path of, you know, algorithm design, sort of-
Brian Kernighan 1:21:19 Not smart enough. (laughs)
Lex Fridman 1:21:21 (laughs) Not smart enough. Wha- uh... (laughs) Uh, you're infinitely, uh, modest. But so you, you pursued your kind of love of programming. I mean, when you look back to those... I mean, just looking
The published transcript ends here. Continue watching on YouTube
Episode duration: 1:43:09
In the uListen app, the transcript lights up word by word as you listen. Get uListen
Transcript of episode O9upVbGSBFo