Writing Small, Focused Changes
What you'll learn: How keeping your code changes small and focused on one logical purpose makes collaboration easier and more effective.
The Core Idea
When you work on a codebase, you'll often be tempted to fix "just one more thing" while you're in a file. You might start implementing a new feature and notice a typo, spot an outdated comment, decide to refactor a function, and add your feature—all in one commit or pull request.
This creates a problem: reviewers now have to understand multiple unrelated changes at once. It's like asking someone to proofread an essay where you've simultaneously corrected spelling, reorganized paragraphs, changed the thesis, and updated citations. Which change caused that test to fail? Which part needs discussion? It's hard to tell.
Why Small and Focused Matters
Single logical purpose means one commit or pull request should do one thing: fix a bug, add a feature, refactor a function, or update documentation—not all four.
Think of it like grocery shopping with a specific list. If you go to the store for milk and come back with milk, new furniture, a subscription service, and a pet goldfish, your roommate will be confused about what you actually needed and why. Small changes are easier to review, easier to test, easier to understand if something breaks, and easier to revert if necessary.
You already learned that pull request size and scope matter. Now you know why: small changes reduce cognitive load, speed up reviews, and minimize the risk of introducing bugs.
In Practice
One bug fix = one PR. One feature = one PR (or split into smaller logical pieces). Refactoring unrelated code? Separate PR. This discipline makes your team faster and your code safer.
Key Takeaway: Keep changes small and focused on a single logical purpose—it makes reviews faster, bugs easier to track, and collaboration smoother.