DEV Community

Jonathan Hall
Jonathan Hall

Posted on • Originally published at jhall.io on

1

4 reasons to change code

Why do we change code?

In his book, Working Effectively with Legacy Code, Michael Feathers offers four reasons:

  1. Adding a feature
  2. Fixing a bug
  3. Improving the design
  4. Optimizing resource usage

I’ve yet to think of a 5th reason.

So what?

These 4 reasons are the basis for a personal rule when writing code:

Each pull request must address only one of these reasons.

Mixing concerns in a single PR can lead to all sorts of problems:

  • It makes the PR much harder to understand and review
  • It makes deploying the PR more dangerous (if a bug is found, is it due to the new feature, or the refactoring?)
  • It makes reverting the PR dangerous (you can’t revert a broken feature without also reverting useful bug fixes)

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay