Chapter 13

The Monday Morning Chapter

You don't rewrite. You strangle.
Demo: 10 methods, 12 sprints: watch the class disappear
☠ class Order
class Order:
def add_item(self, item)
def remove_item(self, sku)
def calculate_total(self)
def apply_coupon(self, code)
def calculate_tax(self)
def calculate_discount(self)
def validate(self)
def serialize(self)
def save(self)
def send_confirmation(self)
Methods remaining: 10
✦ Pure functions
Functions extracted: 0
Sprint 0 / 12
0
Execution ns (class)
0
Execution ns (functions)
0
Test ns (class)
0
Test ns (functions)
Test suite: updates each sprint
☠ Class tests (mock ceremony)
0 passed · 0 ns
✦ Function tests (assert)
0 passed · 0 ns

What you just saw

Each sprint extracts one method from the class into a pure function. The method disappears from the class. The function appears on the right. The class call that used to invoke self.calculate_total() now calls calculate_total(items, coupons, tax_rates). The behavior is identical. The tests still pass. But the function is independently testable, has no hidden dependencies, and can be composed with other functions without instantiating the class.

By Sprint 10, the class is an empty shell: a declaration with no methods. Sprint 11 deletes the class declaration. Sprint 12 is the cleanup: remove the import, delete the file. Twelve sprints. Thirty seconds in the animation. Three weeks in a production codebase.

This is the strangler pattern. You do not rewrite the system. You extract from it, one piece at a time, until the original structure is gone and only the functions remain. Every sprint ships. Every sprint is safe. No big bang. No rewrite. Just steady, incremental improvement that compounds over time.

How this works: This demo uses a cost model to visualize the strangler pattern. Nanosecond values are derived from per-operation costs (vtable dispatch: 15ns, field lookup: 8ns, singleton: 80ns, direct call: 3ns) applied to each method's structure. These are representative costs, not captured traces from a specific harness run. Source: github.com/adamzwasserman/honest-code-traces
← Ch.12: The Declarative Principle Home →