Brian Kernighan *69’s Elements of Style for the Digital Age

Raul Arias

IN THE FALL OF 1996, Brian Kernighan *69 brought scissors, a beard trimmer, and a pair of hedge clippers into the auditorium where he was teaching Harvard’s introductory computer science course, CS50, to more than 450 students. It was Kernighan’s first time teaching a college course — he was employed at the time as a researcher at AT&T Bell Labs — and he decided to use that first lecture to focus on the importance of giving computers specific instructions. He asked the students in the room to direct him in trimming his beard and, when they failed to be sufficiently precise in their directions, ended up cutting his beard with hedge clippers right there at the front of the classroom.

Those students — and hundreds of Princeton students over the last 15-plus years — were lucky to learn from a teacher who also happened to be a pivotal figure in computer programming. In 1978, while at Bell Labs, Kernighan co-authored a seminal book called The C Programming Language with his colleague Dennis Ritchie, who created the language. It was a short book for a programming manual — fewer than 300 pages — and, in fact, it was not so much a manual as it was a friendly and shockingly readable introduction to building basic programs with C.

Brian Kernighan *69, professor of computer science
Ricardo Barros

“Our aim is to show the essential elements of the language in real programs, but without getting bogged down in details, rules, and exceptions,” Kernighan and Ritchie write at the beginning of the first chapter. “At this point, we are not trying to be complete or even precise. ... We want to get you as quickly as possible to the point where you can write useful programs.” The book’s emphasis on providing useful examples and encouraging readers to start writing interesting programs quickly instead of going through an exhaustive list of a language’s features set a new standard for technical writing and a new model for how to teach programming languages.

“I think it’s the most influential book in the history of computers,” says Google engineer Alan Donovan, who co-authored a book on the Go programming language with Kernighan. “That’s not to say it’s the most technical, but it’s the one that most people have read and has shaped the way they feel about computers and learned from and tried to copy in other materials since then.”

The C book introduced the now-ubiquitous “Hello, World!” exercise to fledgling programmers: Walk into any introductory programming class today, and odds are the first assignment will be to use the new language to print those words. It’s also likely that one (or more) of Kernighan’s books will still be assigned as the required text. Kernighan has profoundly shaped how entire generations of programmers have been — and will be — taught. Since leaving Bell Labs to join Princeton’s computer science department in 1999, he has become increasingly focused on changing how non-programmers are taught about computers and technical topics as well.

Through his Princeton course COS 109: Computers in Our World, Kernighan has sought to teach some of the basics of programming, computer technology, and mathematical estimation to students outside the computer science department. Those non-majors, he readily acknowledges, mostly wander into the class looking to fulfill their quantitative-reasoning distribution requirement but often leave with a deeper appreciation of how technology works and what numbers really mean.

Now, with Understanding the Digital World — a version of his previously self-published book D is for Digital: What a Well-Informed Person Should Know about Computers and Communications — set to be published by Princeton University Press in March, Kernighan is hoping to extend some of those lessons beyond the reach of his classroom. Coming from just about anyone else, it would seem like an impossible mission: to write a book about a fast-changing and technical field that introduces readers to a lot of new material without condescending to them or boring them, a book that can boil down to less than 300 pages a massive field and quickly provide readers with the tools to solve and understand real problems. But Kernighan has been writing precisely those kinds of books for more than 40 years.

KERNIGHAN, WHO IS CANADIAN, came to computing relatively late. An engineering physics major at the University of Toronto in the early 1960s, he didn’t even see his first computer — an IBM 650 — until his second year of college, and didn’t start programming until his junior year, when he learned some Fortran. “I was, to put it mildly, pretty bad,” he says of his undergraduate programming efforts. “But it was enough fun that, since I didn’t know what I wanted to do after college, I went to graduate school because it staved off decision-making.”

He arrived at Princeton as a graduate student in 1964 before there was a computer science department. He pursued his Ph.D. in electrical engineering and discovered he loved programming during the summer of 1966, when he worked on a project at MIT and had his first experience with non-punch-card programming, learning the MAD language. “This was in the very earliest days of being able to talk to a computer directly with your fingers at a terminal,” he recalls.

LISTEN: Kernighan speaks about his time as a graduate student on the PAW Tracks podcast

Punch cards would, however, continue to play an important role in his graduate research, and Kernighan, who is passionate about computer fonts and typesetting as well as programming languages, even used punch cards to produce what he suspects is the first machine-readable, computer-printed thesis at Princeton. Rather than typing his dissertation on a typewriter, he used punch cards, essentially large index cards with holes punched in them to represent inputs, to write a program that would format and print his thesis using the sole computer on campus, an IBM 7094 kept in an air-conditioned room in the EQuad. The final version of his thesis, on graph partitioning, required 6,000 punch cards: 1,000 with the typesetting program instructions and another 5,000 with the thesis text.

After he received his Ph.D. in 1969, Kernighan left Princeton for Bell Labs, where he had interned during graduate school. He stayed there for 30 years. During the 1970s and 1980s, perhaps no place in the world was home to as many prominent computer scientists and computer-related inventions and discoveries as Bell Labs. Among Kernighan’s notable colleagues was Richard Hamming, a mathematician who did pioneering work on how computers can identify and correct errors in communications.

“Dick was a classic curmudgeon,” Kernighan says of Hamming. “One of the things he used to complain about was that people were bad programmers. He would say, ‘We give people a dictionary and a set of grammar rules and we say, kid, you’re a great programmer, and that’s ridiculous. We ought to have style guides for programming the same way we have style guides for English.’ ”

Those conversations with Hamming about the need for programming style guides to make people better programmers inspired Kernighan’s first book, in 1974: The Elements of Programming Style, co-authored with P. J. Plauger. Consciously styled on Strunk and White’s guide for writers, The Elements of Style, Kernighan and Plauger attempted to codify general rules for creating code by working through examples of poorly written programs and explaining how they could be improved. Their rules included, “Write clearly — don’t be too clever,” “Make your programs read from top to bottom,” and “If someone could understand your code when read aloud over the telephone, it’s clear enough. If not, then it needs rewriting.” Of the rules enumerated in the book, Kernighan estimates that roughly 90 percent are still applicable, despite the considerable evolution of computing technology and programming since the 1970s.

A recurring theme of Kernighan’s work is the idea that good computer programming is not just about whether your code works, or how fast it runs, but also its clarity and style. That was a prescient realization in the 1970s, when many people did not yet appreciate that software would have the longevity and significance it does today — that many people would have to work on the same programs, year after year.

Over the course of five decades, Kernighan has developed a keen sense of how to derive general, long-lasting principles in a field that has exploded with hundreds, if not thousands, of new programming languages. The new languages often build on older ones, and the foundational rules of style and syntax often still apply. “C is at the base of an enormous amount of what we do in exactly the same way that Latin is,” he says. “There are many languages today that come from Latin, and there are many languages today that come from C.”

This emphasis is undoubtedly one of the reasons that Kernighan’s body of work ages so well in a field that has changed dramatically since his career began. Today, very few people rely on printed books or manuals to help them program. Instead, they search through forums on websites like Stack Overflow to find other people who have asked the same questions, and get feedback on their code. The programming language manual is all but obsolete — and yet Kernighan’s books are as relevant as ever: their principles general enough to transcend the decades and insightful enough to offer something the thousands of answers available in online forums cannot.

Kernighan’s ideas about the value of style for programming languages were, in large part, articulated before maintaining and developing code became such a vital activity and stemmed from a more basic insight: that clear use of language leads to clear thinking, and vice-versa.

“Programming style is first for the person who wrote the code, because I might write this program today and then put it aside and come back to it a few years later,” Kernighan says. “The better it’s written, the more I’ve adhered to these rules of style, and tried to be clear and simple, the more likely it is that I will be able to understand it — and the more likely it is that it will work properly. And the more likely it is that other people will be able to understand it.”

NOT EVERYONE WANTS TO WRITE CODE. During the semester he spent teaching at Harvard, Kernighan discovered how much he enjoyed teaching, but also found it challenging to design an introductory course that worked for aspiring computer scientists as well as students in other fields who just wanted some basic understanding of computing.

“There was a population that was not well served by [CS50],” Kernighan recalls. “When I came to Princeton, I decided I wanted to create a course that would serve those students.” The course he developed, COS 109, is aimed at students who are intimidated by math or computer science and want a gentler introduction to computing topics. It covers topics that range from how to estimate and understand large numbers to legal and privacy issues surrounding computers, as well as some basic coding in Javascript.

“The presiding thesis behind that course is to say computer science and computing technology underpin almost everything that makes society tick in the 21st century, and yet so few people actually get how it works and understand what goes on behind the surface,” says Elizabeth Linder ’07, who majored in French and Italian and took COS 109 her freshman year. She went on to work at Google and Facebook for several years before founding a media and leadership advisory firm called The Conversational Century. Working with governments and political leaders on issues related to technology, Linder often drew on her experience in Kernighan’s class. “I think back often to Professor Kernighan who, on a different and deeper level, was doing a very similar thing to what I do now — helping to translate the world of computer science for a group of people to whom that doesn’t come naturally,” she says.

Even when he’s not teaching, Kernighan’s work often involves finding new ways to convey important computing concepts or programming languages to a wider audience. He recently co-authored The Go Programming Language with Donovan (“It was like writing a first novel with J.K. Rowling,” Donovan said of the experience, offering some sense of how much Kernighan and Ritchie’s book is revered by programmers). In D Is for Digital Kernighan’s focus is also educational, though he’s not trying to teach readers how to program so much as he is trying to help them understand what it means to program or use technology — all while maintaining his characteristic brevity, clarity, and lack of condescension.

Madeleine Planeix-Crocker ’15, a French and Italian major, proofread the second edition of D Is for Digital after taking COS 109 during her sophomore year. Since graduating, she has made use of her COS 109 Javascript training in her current job doing back-end website management for an art foundation in Paris. But beyond helping prepare her for that role, she says, Kernighan’s course was valuable to her in providing some history of technology and how it has changed over time. “I now understand the stakes which accompany the evolution of technology in society,” says Planeix-Crocker.

Kernighan had a profound impact even on some of his earliest students, including those in that 1996 class at Harvard. David Malan, a sophomore majoring in government at the time, took the class only because Kernighan let him take it pass/fail; he ended up loving it and ultimately switched his major to computer science. Now a professor of computer science at Harvard, Malan has been teaching the CS50 course ­­— the largest class at Harvard — for a decade.

“There was a friendliness to that class,” Malan said of taking CS50 with Kernighan. “He would have one of the teaching fellows walking around giving candy to the people who asked questions, and I still remember the day I got up the nerve to ask a question in front of my hundreds of classmates. That was the beginning of my taste of community in a class. A lot of the things we do now in CS50 are sort of in the spirit of that, like giving out stress balls and little rubber ducks to students.”

Years later, Kernighan’s students recall how he regularly asked after their siblings, attended their plays, and knew the names of everyone in his class. Taped above his desk in the computer science building are large photographs of his current students. “The things I’ve learned about teaching are fundamentally to get to know the students, because if they’re a name and a person then you do a better job,” Kernighan says. “Other than that, jeez, I don’t know, try to be organized, and let them out early.” 

Josephine Wolff ’10 is an assistant professor of public policy and computing security at Rochester Institute of Technology.