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 8. Code That Isn’t Running Doesn’t Work

Any big codebase, especially one that’s been around a while, has dead ends in it: lines of code, or functions, or subsystems, that aren’t getting exercised any more. Presumably they were added for a reason—at one point, those lines of code were getting called. Things change, though, and at some point whatever code was calling no longer needs to. The calls stop coming. The code has been orphaned.

Sometimes the orphaning is obvious, like a function that isn’t called from anywhere else in the program. If your language and toolchain are robust enough, you might even get a warning about this particular kind of dead code.

More typically, the orphaned code isn’t that obvious. It might still be mechanical, like a virtual method defined in a base class that is never called for a particular derived class. Static analysis can’t pick up that sort of thing up. Or there’s code written to handle some special edge case in a function, a scenario that requires special conditional handling. At some point, things change and that scenario can no longer occur. The edge case code is still sitting there, but it’s never called.

The closer you look at any mature codebase, the more orphaned code you find—like enumerated values that are defined but never used, or special-case code targeted at an old version of a library you haven’t used for years.

This sort of evolution of code is both natural and inevitable. The codebase is a river, winding its way back and forth ...

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