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 2. Bugs Are Contagious

There’s a truism of programming that the earlier you find a bug, the easier it will be to fix. That’s generally true…but I think it’s even more true to say that the later you find a bug, the more of a pain in the ass it will be to fix.

Once a bug exists, people will unintentionally write code that relies on that bug. Sometimes that shaky bit of bug-reliant code is nearby, in the same system as the bug. Sometimes it’s not nearby—maybe it’s downstream, in a bit of code that calls your system and depends on the incorrect results your bug causes. Or it’s upstream—a chunk of code that only works because the bug caused you to call it in a particular way.

This is a natural thing—it’s impossible to avoid. We notice things that go wrong, not things that go right. When things go wrong, we investigate to figure out why. But when things don’t go wrong, we don’t investigate. If your code works, or at least seems to work, then there’s a natural tendency to assume that it works in the way you think it works, when very often it works for reasons you’ve never imagined. And since you don’t investigate, you never discover the tangled set of circumstances that led to your code accidentally working.

That’s true for the code you write, and it’s true for the code other people write that calls your code. When you commit a bug to your team’s codebase, the codebase will slowly but inevitably accumulate other bits of code that rely on your bug. These hidden entanglements only ...

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