software-design/refactoring-tidy-messy-code-without-breaking-it-using-tests-as-a-net.md
Refactoring: tidy messy code without breaking it, using tests as a net
Refactoring means changing how code is written without changing what it does, so the next person (often you) can read it. It sounds risky, and it is, unless you have a safety net.
Here you get a messy shipping cost function, eight tests, and a live editor. Tidy the code step by step and watch the tests stay green, then try a "harmless" edit that quietly breaks one rule and see exactly which test catches it.

$ ls software-design/
see all →
software-design/your-first-unit-test-catch-the-leap-year-bug-a-quick-check-misses.md
Your first unit test: catch the leap-year bug a quick check misses
A unit test is a tiny piece of code that checks another piece of code: you pick an input, write down the answer you expect, and let the…
software-design/how-to-read-a-python-error-message-without-panicking.md
How to read a Python error message without panicking
When Python crashes it prints a traceback: a report of what went wrong and where. It looks scary, but it has a fixed shape, and the most…
software-design/functions-why-you-should-stop-copy-pasting-your-code.md
Functions: Why You Should Stop Copy-Pasting Your Code
Copy-pasting code works fine on the day you do it. It fails the day you need to change it, and have to find and fix every copy without…