An Interview with Alexander Stepanov and Paul McJones on Elements of Programming
Andrew Binstock: Alex, people know you for your work on the Standard Template Library (STL) in C++. I suspect most readers have not heard much about your subsequent work. Could you update us on what you’ve been doing?
Alexander Stepanov: I have been searching for principles to decompose software into components since the late 1970s. STL was an example of that. While intended to be a useful library, it was also intended as a model for others to build such components. After the STL became successful, I realized that people were using it without attempting to design their own software using the same principles. Fortunately I was given the opportunity at SGI to spend several years teaching very experienced compiler engineers these techniques. When I came to Adobe I was again asked to focus on teaching engineers (specifically Photoshop and the advanced graphics development team) these programming techniques. While not everyone liked the approach, many—I would even say the majority of engineers—told me that it changed their view of programming. It was rewarding for me that programmers with advanced degrees and years of experience were willing to attend the lectures and do challenging homework for a year or even more in addition to their busy product development schedule. Therefore when Adobe management suggested I write a book, it seemed a worthwhile undertaking.
Andrew: What are you currently working on at Adobe?
Alex: I’ve been teaching advanced programming classes and developing an overall curriculum for Adobe engineers. Now I’m in transition to a new role.
Andrew: Paul, I suspect you’ll be less familiar to readers than Alex. Your site, mcjones.org/paul, presents your long history of working with operating systems and language tools, especially Modula 2 and Modula 3. Can you fill that in a little and tell us how you came to be Alex’s co-author?
Paul McJones: After attending Alex’s course at Adobe for a few months, I realized that he was developing rigorous answers to questions about how to decompose software that had concerned me since I worked with John Backus in the mid 1970s on functional programming. It turns out that John’s work on FP was one of the major inspirations for Alex in the late 1970s. Alex’s original intuition was to associate specific functional forms (for example, reduction) with algebraic properties of specific functions (such as associativity). In retrospect, there are interesting parallels on the one hand between my conversations with John, and my earlier attempts to extend APL operators while working on an APL virtual machine at U.C. Berkeley, and on the other hand between Alex’s insights about John’s work, and with Alex’s discussion with Iverson about defining new operators. Thus it was an honor when Alex invited me to coauthor the book with him in early 2007. While I had no STL and little C++ experience before taking his course, my work specifying Modula-3 library interfaces gave me some confidence that I could contribute to the effort.
While Alex makes effective use of stories in his lectures, I was uncomfortable with the somewhat self-indulgent, conversational style in Alex’s written lecture notes. I advocated the impersonal style used in the mathematics and computer science books from my college courses in the 1960s. Alex quickly agreed, and we evolved a style that we both find appropriate.
Andrew: I see that in addition to being a co-author, you manage the collection of Alex’s papers. Is there a Boswellian element to your work with him? Do you work together on a regular basis at Adobe? If so, what do you work on together?
Paul: I have been interested in the history of software for some years. (See for example my collection of the original IBM 704 Fortran compiler at the Computer History Museum.) When I began attending the course Alex was teaching at Adobe, I became interested in how his work had evolved since the late 1970s, leading me to organize the Collected Papers web site. I learned from Alex’s lectures how his study of the history of mathematics, extending back to the Greeks and before, is integral to his view of mathematics and programming. So both of us could be called historically informed computer scientists. While we removed all the historical anecdotes that appear in Alex’s lectures, we still feel the book is grounded in thousands of years of mathematics and some 60 years of computer science history.
Andrew: What are you currently working on at Adobe?
Paul: Before Elements of Programming, I was one of the designers and implementers of Adobe’s Pixel Bender language. Now I too am in transition to a new role.
Andrew: Your new book, Elements of Programming, appears to be an attempt to map programming logic to principles of mathematics and formal logic and thereby establish the correctness of various code elements. Why did you write this book and what need does it fill?
Alex: We do not need to map programming to mathematics. Programming by its nature is a mathematical discipline, since programs manipulate abstract mathematical objects such as integers, shapes, sequences, etc.
Paul: We take well-known programs such as min and max, greatest common divisor, and binary search, and show their true mathematical settings. As mathematics helps mechanical engineers build bridges that do not collapse, mathematics helps programmers build dependable software.
Andrew: The book, while short, is a very difficult read and requires considerable a priori schooling in formal logic and abstract algebra. What benefit does a practitioner derive from working through it? How would a working programmer’s way of thinking change as a result of reading the book?
Alex: The book is difficult; there is no easy road to programming. Everything that goes beyond high school mathematics (elementary geometry and algebra) is defined in the book.
Paul: Working through the book teaches how to reason about code, how to find sets of useful interfaces, and how to design powerful and efficient components that can work together.
Andrew: Were you concerned that developers, even those with extensive computer science backgrounds, might be flummoxed by sentences such as “A discrete Archimedean semiring lacks additive inverses...” (p. 86). This quotation and others suggest that the real audience for this book is mathematicians rather than computer scientists. Whom do you have in mind as the intended reader?
Alex: As we say in the preface, the book must be read sequentially. Taken out of context that sentence might scare someone, but a reader will have previously learned that a semiring is a type combining addition and multiplication and that the Axiom of Archimedes allows division with remainder. While some mathematicians might benefit from the book as a way to learn about programming, the book is primarily targeted at programmers.
Paul: The evidence from the courses at SGI and Adobe is that determined programmers with computer science degrees can work through this material. But, yes, it does require an effort. On a personal note, I forgot the little abstract algebra I learned in college, but had no difficulty relearning the material.
Andrew: I am surprised that you did not include a glossary for these definitions. Do you not view this as a book that might be used for subsequent reference? Or should we infer from this aspect and from the exercises that you intended this to be primarily or exclusively used as a textbook?
Paul: Mathematicians have created a large taxonomy of concepts. The purpose of this book is to demonstrate how to adapt part of the taxonomy to organize software components. The book is not intended to be a reference book; for example, it does not define fields (such as reals), multidimensional structures, and stops just a bit short of defining Quicksort.
Alex: It is, as it were, a prolegomena to any future reference on software components.
Paul: And rather than a glossary, we have a detailed index.
Andrew: You say, “The purpose of this book is to demonstrate how to adapt part of the [mathematician’s] taxonomy to organize software components.” Of the many things one hears developers needing, organizing software components is not often listed. How is this need apparent? And how does this book answer that need?
Alex: A colleague of ours at a prominent software company recently reviewed a complex piece of code. He observed that it was equivalent to a call of find_if followed by a call of rotate; it took him a week to convince the other programmers of this equivalence. If those programmers had read our book they would recognize this fact.
Paul: In general, programmers should avoid inventing components or taxonomies, for that matter, but should recognize the well-known ones, just as mathematicians have been building on their predecessors’ work for centuries.
Andrew: Are the answers to the exercises available on-line? If so, where?
Alex: It might be valuable to have an edition containing proofs of all the lemmas and answers to all the exercises, but we do not have immediate plans to work on it.
Paul: Note that eop.h on the website has many additional algorithms mentioned in the text or assigned as exercises.
Andrew: In working on the code for the book, how did you test it?
Paul: First, we used “pair programming”; both of us read and reread every line of every program many times. Second, we wrote unit tests, which are available along with the code from the book on http://www.elementsofprogramming.com. We used gcov to check the coverage of our unit tests.
Alex: Sadly, we are sure there are still some undiscovered bugs. We keep the errata up-to-date on the web site.
AB: Paul, you’ve implemented several languages on several platforms. In this book, you and Alex chose C++ as it had the capabilities needed to demonstrate the techniques you were illustrating. What aspects of C++ made it your choice for this book?
Paul: The ability to overload functions and operator symbols allows us, when defining a particular concept, to specify the signatures of the operators and functions that must exist for any type modeling the concept. The ability to define new types with copy constructor, assignment, and equality modeling the regular concept means types defined by the programmer behave the same way as built-in types like int. The ability to pass arguments by reference means that we can work with regular types efficiently.
Alex: I’d like to remind you that C++ is not an object-oriented language, but a multi-paradigm language with features that supports object-oriented style of programming: inheritance and virtual functions. We don’t use these features. To summarize, we know how to say what we want in C++ but do not know how to say it in other languages. It helps that C++ is a language familiar to programmers at Adobe, where most products are implemented in it. Note, however, that the fundamental concepts we define come from mathematics, not from C++ or any other programming language.
Andrew: Alex, you’re known in part for your strong negative opinions about OO “I find OO technically unsound, methodologically wrong, etc.” Yet you still chose a subset of C++ for the code. Does this choice reflect any change in your feelings about OO?
Alex: The book is about programming as algorithms and data structures viewed as a mathematical activity, not about language techniques. A small subset of C++ that does not include any object-oriented features allowed us to say what we wanted. There are cases where object-oriented features are useful, but they are often oversold.
Paul: I should add I entered the project without extensive C++ experience, and found our subset to be natural and powerful.
Andrew: In the book, preconditions are integrated into many of the code snippets. The explicit use of preconditions is reminiscent of design by contract (DBC). Were you tempted at all to use a language such as Eiffel in which you could have stated pre- and post-conditions, as well as the “contract terms” or a Knuth-like solution of inventing your own language for purpose of illustrating code?
Paul: We spent a lot of effort on everything from selecting a small set of control statements, expressing pre- and post-conditions, and specifying the requirements (concepts) on the types used by an algorithm. We are happy with the result: a small subset of C++ extended with informal but consistent conventions for defining concepts and using them to specify type requirements. The code all compiles and runs; we find it quite readable.
Alex: While it is possible that in the future there will be a language that could better support this style of programming, we think that language design should follow, rather than precede, learning this style and applying it to components and programs. An appropriate programming language needs to be distilled from a large body of programs. But we do not need to wait for the creation of such a language. Scientists and engineers have been able to apply mathematics to physics, chemistry, civil engineering, and so on without creating a formal language. Instead, the informal but rigorous approach to definitions, theorems, and proofs used by mathematicians since Euclid provided a very solid foundation for many areas of science and engineering.
Andrew: Alex, the book, it seems, extends your work with generic programming using as illustration small, discrete algorithms. How would a developer use these techniques for attacking more-complex tasks?
Alex: First I need to clarify the term “generic programming.” Dave Musser and I introduced it in the late 1980s to mean a style of programming based on decomposing software into highly reusable and efficient components. Now, the term often signifies a set of techniques that are neither highly reusable nor efficient. Therefore, Paul and I decided not to use the term in the book. Moreover, both of us believe this is not just a style of programming, but programming as it must be: always trying to get to the essence of every algorithm.
A reader of the book will learn that even a task as simple as defining min and max is difficult—I got it wrong in STL, and nobody noticed! There are more difficult tasks than min and max, but the same reasoning applies to them. The book also demonstrates how to decompose complicated algorithms into simple steps.
Paul: Consider, for example, writing the two-line sort_n at the end of chapter 11 without any of the algorithms developed before that point.
Andrew: Is there a design-level equivalent to generic programming? That is, at the level of designing modules and their interaction?
Paul: We follow Wirth in believing that algorithms and data structures constitute the essence of programming. I haven’t seen any barriers to this approach.
Andrew Binstock is best known for his long-running column in SD Times and for his reviews in InfoWorld. Prior to his current work, he was head of Technology Forecasting for PricewaterhouseCoopers. Earlier he was the editor in chief of UNIX Review for many years, and previously founded the C Gazette. He is the co-author of “Practical Algorithms,” which went through 14 printings before becoming part of the long tail. When not writing, he’s a committer on the Platypus project, (http://platypus.pz.org) an open-source page-layout and typesetting package.