DEV Community

Daniel Wildt
Daniel Wildt

Posted on

How To Feel Safe While Modifying Code?

Every time someone is updating a codebase, there’s this old saying from eXtreme Programming that we are doing it with value of courage.

But that’s not just guts to do something.

And by the way, the safe way of modifying code is finding ways to not modify the code. 🫠

If that’s not the case, let’s continue.

The courage comes from safety. The understanding that we have a set of automated tests that works as a safety net.

I modify existing code adding a new scenario that will fail when I run it against the codebase. If it gets red, I’m free to change the behavior. When I do it correctly, I will get a green with tests passing again. Now I’m free to refactor and change structure, without changing the behavior.

It’s pure Test Driven Development (TDD) red-green-refactor cycle.

This is also a cycle that gives me courage to keep going, if I need to add new business rules to the current code.

But, what if there’s no automated tests in place?

We can create a “thin ice” like set of tests, just to help us in the process. We can also look for a pair programming session with someone who knows about the codebase.

Maybe an exploratory test session can help us understand how the addition will affect other parts of the system, since we only have a small part of the system covered with automated tests.

Make sure you are also adding lints and other code audit tools to help you understand about code health. Tools like drTools or Sokrates can help us a lot, depending on the programming language in use.

-- Daniel Wildt

Top comments (0)