đ Hi, this is Ryan with this weekâs newsletter. I write about software engineering, big tech/startups, and career growth. Thank you for your readership, we hit 48,000 readers this week đ đ
This week, I wrote about why small diffs are best. If you find the post helpful, please share it with your friends and coworkers. Enjoy!
Note: âdiffsâ == âcode changesâ == âPRsâ
After writing over 1000 diffs, I prefer smaller ones. Often thereâs wisdom in what you naturally tend towards over time. This preference developed after lots of feedback and tweaks.
Having lived this process, itâs clear to me that all engineers should be writing small diffs where possible. If you havenât written enough code to feel the benefits, let me try to convince you. Hereâs why you should keep your diffs small.
1. Small diffs are reviewed faster. Once youâre comfortable with your codebase, youâll realize the bottleneck for landing code quickly isnât in how fast you can write it. Often itâs in waiting for people to review it.
The smaller your diffs are, the more willing people are to review them. Iâll even add â[easy]â to the title for my shortest diffs to advertise this.
2. Small diffs are reviewed more thoroughly. The larger a change is, the more likely a reviewer is to skim the contents. This lets low-quality code slip through the cracks:
You should encourage feedback. A true test of your code quality is if it invites feedback yet receives none.
3. Small diffs cause fewer bugs. The less a diff does, the easier it is to understand its effects. This makes it easier to test and confirm the code does what is intended.
4. Small diffs have fewer merge conflicts. Big changes have more surface area and take longer to write. That increases the chance of someone changing code while youâre working on it. When you finally try to land that change, youâll have merge conflicts to deal with which wastes time.
5. Small diffs are easier to roll back. A simple way to fix broken code is to revert to before the breakage. This can get complicated if the bad diff is large since itâs more likely changes landed on top of it that also need to be reverted.
This doesnât mean there isnât a place for large diffs. Sometimes it makes sense if youâre landing a bunch of boilerplate or auto-generated code. As a rule of thumb though, your diffs should aim to do just one thing.
If you found this useful, please share it with a friend and consider subscribing if you havenât already.
Thanks for reading,
Ryan Peterman
Might be exaggerating, but Iâve always said that the best diff/PR size is the one that fits the smartphone screen or possible to review on the go :)
Spot on, Ryan! Long diffs have a higher chance of a random LGTM occurring than smaller diffs! Because I self-review my PRs before requesting reviews, I'm encouraged to make those smaller diffs anyway. đ