Skip to Main Content
The Rules of Programming
book

The Rules of Programming

by Chris Zimmerman
December 2022
Beginner content levelBeginner
343 pages
7h 36m
English
O'Reilly Media, Inc.
Audiobook available
Content preview from The Rules of Programming

Rule 1. As Simple as Possible, but No Simpler

Programming is hard.

I’m guessing you’ve already figured this out. Anyone who picks up and reads a book titled The Rules of Programming is likely to both:

  • Be able to program, at least a little

  • Be frustrated that it’s not easier than it is

There are lots of reasons why programming is hard, and lots of strategies to try to make it easier. This book looks at a carefully selected subset of common ways to screw things up and Rules to avoid those mistakes, all drawn from my many years of making mistakes of my own and coping with the mistakes of others.

There’s an overall pattern to the Rules, a common theme that most of them share. It’s best summarized with a quote from Albert Einstein describing the goals of a physical theorist: “As simple as possible, but no simpler.”1 By that, Einstein meant that the best physical theory was the simplest one that completely described all observable phenomena.

Recasting that idea to programming, the best way to implement a solution to any problem is the simplest one that meets all the requirements of that problem. The best code is the simplest code.

Imagine that you’re writing code to count the number of bits set in an integer. There are lots of ways to do this. You might use bit trickery2 to zero out a bit at a time, counting how many bits get zeroed out:

int countSetBits(int value)
{
    int count = 0;

    while (value)
    {
        ++count;
        value = value & (value - 1);
    }

    return count;
}

Or you might opt ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Programmer's Brain

The Programmer's Brain

Felienne Hermans
Design It!

Design It!

Michael Keeling
The Art of Clean Code

The Art of Clean Code

Christian Mayer

Publisher Resources

ISBN: 9781098133108Errata PageSupplemental Content