software-design/pure-functions-why-the-same-call-can-give-two-different-answers.md
Pure functions: why the same call can give two different answers
Call a function twice with the same input and get two different answers? Python isn't broken. The function is doing something extra, called a side effect.
A pure function only uses its arguments and changes nothing else, so it always answers the same way. Try three small Python functions, compare each with a pure rewrite, and see why pure ones are easier to predict and test.

$ ls software-design/
see all →
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…
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…