Jump to ratings and reviews
Rate this book

Elements of Programming

Rate this book
“Ask a mechanical, structural, or electrical engineer how far they would get without a heavy reliance on a firm mathematical foundation, and they will tell you, ‘not far.’ Yet so-called software engineers often practice their art with little or no idea of the mathematical underpinnings of what they are doing. And then we wonder why software is notorious for being delivered late and full of bugs, while other engineers routinely deliver finished bridges, automobiles, electrical appliances, etc., on time and with only minor defects. This book sets out to redress this imbalance. Members of my advanced development team at Adobe who took the course based on the same material all benefited greatly from the time invested. It may appear as a highly technical text intended only for computer scientists, but it should be required reading for all practicing software engineers.”
—Martin Newell, Adobe Fellow

“The book contains some of the most beautiful code I have ever seen.”
—Bjarne Stroustrup, Designer of C++

“I am happy to see the content of Alex’s course, the development and teaching of which I strongly supported as the CTO of Silicon Graphics, now available to all programmers in this elegant little book.”
—Forest Baskett, General Partner, New Enterprise Associates

“Paul’s patience and architectural experience helped to organize Alex’s mathematical approach into a tightly-structured edifice—an impressive feat!”
—Robert W. Taylor, Founder of Xerox PARC CSL and DEC Systems Research Center

Elements of Programming provides a different understanding of programming than is presented elsewhere. Its major premise is that practical programming, like other areas of science and engineering,must be based on a solid mathematical foundation. The book shows that algorithms implemented in a real programming language, such as C++, can operate in the most general mathematical setting. For example, the fast exponentiation algorithm is defined to work with any associative operation. Using abstract algorithms leads to efficient, reliable, secure, and economical software.

This is not an easy book. Nor is it a compilation of tips and tricks for incremental improvements in your programming skills. The book’s value is more fundamental and, ultimately, more critical for insight into programming. To benefit fully, you will need to work through it from beginning to end, reading the code, proving the lemmas, and doing the exercises. When finished, you will see how the application of the deductive method to your programs assures that your system’s software components will work together and behave as they must.

The book presents a number of algorithms and requirements for types on which they are defined. The code for these descriptions—also available on the Web—is written in a small subset of C++ meant to be accessible to any experienced programmer. This subset is defined in a special language appendix coauthored by Sean Parent and Bjarne Stroustrup.

Whether you are a software developer, or any other professional for whom programming is an important activity, or a committed student, you will come to understand what the book’s experienced authors have been teaching and demonstrating for years—that mathematics is good for programming, and that theory is good for practice.

262 pages, Hardcover

First published January 1, 2009

86 people are currently reading
1164 people want to read

About the author

Alexander Stepanov

13 books13 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
69 (35%)
4 stars
74 (38%)
3 stars
31 (16%)
2 stars
13 (6%)
1 star
6 (3%)
Displaying 1 - 15 of 15 reviews
22 reviews3 followers
April 20, 2016
This one was a bit of a slog. Because it tries to be both a Mathematics and a Computer Science book, it skims a little over both, and I can't honestly recommend it unless you have a little background in both areas (which seems likely, if you are considering this). For instance, it uses the taxonomy of algebraic structures (monoids, groups, rings), with requirements on operations (associativity, commutativity, existence of identity, existence of inverses) to illustrate constructing a taxonomy of concepts that apply to data structures, but it doesn't dedicate much explanation to the mathematical structures, so you can only really follow if you already know them.

In the other direction, it is also not a book from which to learn algorithms or C++ template metaprogramming techniques, at least from scratch, although you will learn something about those. If you already have some idea about how gcd, rotate, and partition work, then you should be reasonably well set to learn a lot more about possible implementation variations, with their respective asymptotic complexities and requirements on the types on which they operate.

Some of the above might seem negative, but I simply want to point out what the book is not. What it is, is an excellent academic guide to carefully designing simple components, and building complex behaviour out of those, along with a catalogue of some useful such components. I learnt a lot about fundamentals such as partitioning, sorting, vectors, and deques. One key component that Stepanov has talked about a lot, but that didn't seem to get quite as much stress here, is his associative binary counter, absolutely essential for efficient iterative reduction. I found the description in this book finally made this idea click, even though I had seen it several times before.
Profile Image for Nick Black.
Author 2 books891 followers
January 2, 2011
did i never review this??! i thought for sure i had! oh man this is the book god read before he coded the universe. sloooow going, but don't be daunted.
---
Amazon 2009-07-07. I'm looking forward to this being the most exciting thing I've read in months, maybe years.
12 reviews1 follower
March 7, 2017
The name is misleading. It's more like a theoretical background beyond STL
Profile Image for Gary Lang.
255 reviews36 followers
February 7, 2016
You might enjoy the combination of math theory and applying it to practical coding. If you do, then you should love this book. Usually stuff like this doesn't have as much application to real life (see Z Notation).

I had forgotten how elegant C++ templates could be; reading this brought it all back.
Profile Image for Christian Kotz.
22 reviews1 follower
March 25, 2016
excellent, must read for computer scientist. Very systematic and mathematical. It is from the designer of the C++ Standard Library, which shows its relevance for real world programming, despite its mathematical character.
Profile Image for 0xd34df00d.
43 reviews8 followers
November 17, 2025
C++ programmers discovered that math exists, and yet somehow managed to turn it into ad-hoc unreadable mess. This is the C++ way.

I mean, when a book "addressed to those who want a deeper understanding of programming, whether they are full-time software developers, or scientists and engineers [who practice programming]" starts like this, you know you're in for a good time:

In order to explain what objects, types, and other foundational computer notions are, it is useful to give an overview of some categories of ideas that correspond to these notions.

An abstract entity is an individual thing that is eternal and unchangeable, while a concrete entity is an individual thing that comes into and out of existence in space and time. An attribute—a correspondence between a concrete entity and an abstract entity—describes some property, measurement, or quality of the concrete entity. Identity, a primitive notion of our perception of reality, determines the sameness of a thing changing over time. Attributes of a concrete entity can change without affecting its identity. A snapshot of a concrete entity is a complete collection of its attributes at a particular point in time. Concrete entities are not only physical entities but also legal, financial, or political entities. Blue and 13 are examples of abstract entities. Socrates and the United States of America are examples of concrete entities. The color of Socrates’ eyes and the number of U.S. states are examples of attributes.

An abstract species describes common properties of essentially equivalent abstract entities. Examples of abstract species are natural number and color. A concrete species describes the set of attributes of essentially equivalent concrete entities. Examples of concrete species are man and U.S. state. A function is a rule that associates one or more abstract entities, called arguments, from corresponding species with an abstract entity, called the result, from another species. Examples of functions are the successor function, which associates each natural number with the one that immediately follows it, and the function that associates with two colors the result of blending them.

An abstract genus describes different abstract species that are similar in some respect. Examples of abstract genera are number and binary operator. A concrete genus describes different concrete species similar in some respect. Examples of concrete genera are mammal and biped. An entity belongs to a single species, which provides the rules for its construction or existence. An entity can belong to several genera, each of which describes certain properties.


Stepanov absolutely loves ontologies. Inventing your own ontologies makes you sound smart and wise, even if those ontologies are imprecise. Or unsound. Or unused, even! The only other place that mentions "genus" or "genera" is the phrase saying that "concepts are genera". That's it. I've searched the whole book, but that's the only place, and it doesn't even mention if these genera are abstract or concrete. Sure, this single usage absolutely warrants introducing the term by examples and wasting a dense paragraph right in the intro.

A proper type theory with proper universe levels that's defined axiomatically? Nah, who cares about that nonsense. Let's hack something together via a few examples and call it a day.

And then you also have regular stuff, semiregular stuff, pseudotransformations, halvable monoids, dynamic composite linearizable objects and whatnot (at least I'm glad there aren't any pseudototal functions, but then maybe there are). Science is when you sound smart. The more dictionary lookups you have to do to understand a phrase and the more modifiers you slapped onto your terms, the more science you do. Bonus points for making loops in the definitions — that's Nobel-tier science. Or Fields-tier. Or both.

And then there is terrible code with single letter identifiers, gotos, funny formatting, and UBs for additional bonus points.

I don't know who this book is really aimed at. I doubt your average C++ programmer will look at this and say "yeah, I'm now interested in math, lemme grab a book on abstract algebra". I doubt your average scientist or engineer will look at the code and say "yeah, that's legible, I've improved my programming skills today". I doubt your average math-inclined scientist will find the first few chapters on "halvable monoids" useful. I doubt a non-inclined scientist will care at all.

Maybe the real audience is the author. He has a book full of ontologies after all!

Yet, this is the book in the C++/STL/generic programming community. I've heard high praises, but not high critique. This perhaps explains why C++ is in such a sad and sorry state.

This is abysmal. I wish this site had 0 as a legit rating.
1 review1 follower
June 3, 2019
Книга неплоха, но тяжела для чтения без необходимости.

Основное внимание уделено отношению между математическими концепциями, их выражением в ЯП и непосредственно структурами в памяти. Это довольно интересный топкик, обычно как в литературе так и во всяких блого-конференциях один из аспектов начисто игнорируется. Содержание построено грамотно и в принципе старается идти от простого к сложному. Автор не пытается объять всё сразу, а плавно строит инструментарий и применяет его в простых но имеющих смысл для бывалого программиста задачах. Математические аспекты напоминаются бегло и немного путанно, видимо пару раз на почитать чтонить по алгебре придётся отвлечься.

Язык крайне тяжёл. Много собственной терминологии. Причём термины многословны и похожи, много времени тратится на листание назад в поисках определения. Можно было радикально упростить восприятие небольшими врезками с напоминанием терминологии. Также не хватает диаграмм, особенно при обсуждении бифуркатных координат, переупорядочений и вспомогательных "машин". Пришлось много рисовать самому чтобы въехать.

В общем типичный экземпляр позднесоветской литературы. Если есть хорошее представление что хочешь от книги получить и тебе повезло быть с автором примерно на одной волне то можно подчерпнуть много интересных идей. Если нет - идите нахер, у нас тут фундаментальное образование, мы тут не развлекаться собрались, надо привыкать страдать.

Можно рекомендовать для расширения сознания.
Profile Image for Maxim Chetruşca.
32 reviews20 followers
August 9, 2017
A very complex book. I think its description promises more than it delivers. The language used by the author is pretty difficult to understand. The path from chapter to chapter and through a chapter is not always clear, you don't understand where the author is going with it. I definitively did not understand a lot.
Profile Image for Mark.
36 reviews
December 24, 2012
Brilliant! A synthesis of practical programming and rigorous mathematics. No head-in-the-clouds formalisms like the lambda calculus or Turing machines here, this is the thinking that directly inspired C++ templates and the STL. A word of advice - take a course in abstract algebra before reading this, and it may make much more sense.
Displaying 1 - 15 of 15 reviews

Can't find what you're looking for?

Get help and learn more about the design.