Leave Code a Bit Better Than You Found It

AI is transforming developers into a new and unseen mixture between developer, team lead and product manager.

Running agents can be compared to running a team of developers: just as the quality of their output varies from one contributor to another, an agent’s output can vary from one session to the next.

It is therefore not uncommon to find aberrations in the code written by your agents from time to time. Things that make you think “how the heck did this get merged into the codebase?”

While not ideal, this is not something to obsess about, as only allowing perfect code to be merged would halt the natural development process of the product—which will inevitably acquire imperfections as time goes by.

The approach I like to use when facing this situation is an idea I heard from Uncle Bob Martin: “leave it better than you found it.”

When finding an aberration, do not despair or take it personal, but do a little extra work to leave the code a little bit cleaner than it was before your PR.

This is similar to the process of gardening: the garden will never be 100% perfect, but you can always correct what you find and keep it as close to perfect as you can.

Not letting any imperfect code enter the codebase reminds me of the quote “do not let ‘perfect’ be the enemy of ‘good.’”

Development must keep going. Products must keep evolving. Making everything perfect before shipping is a trap to stop the important work that needs to be done, and the remedy is simple: commit to cleaning the aberrations every time you find them and, as Uncle Bob would say, leave the code a bit cleaner than you found it. That’s a much better approach.

Did you like this article?