logo
podcast Podcast
get help Get Unstuck

Letting the code sit a while before refactoring

An experiment with some ugly code

Joel Clermont
Joel Clermont
2025-01-10

I was recently working on a project with a hard deadline. Some API automation had to be complete before someone went on vacation, or else it would mean a lot of manual work in their absence.

Thankfully, I got the feature built in time, and it was properly covered with tests, so I had confidence it was working as expected, even the edge cases.

But I'll be honest, I was not happy with how the code was structured. The API I was integrating with served up some less-than-ideal XML payloads, and it took quite a bit of conditional logic to get the implementation working in all cases.

So while I got it deployed for the deadline, and it's working as expected, my plan was to refactor it the next day, while it was fresh in mind. I had my test coverage in place, so I could confidently rebuild the XML parsing, and know nothing changed or broke.

But when I mentioned this to Aaron, he suggested I "let the code sit for a while" before jumping right back in to refactor. His argument was that giving it a little space could lead me to a better solution, one that wouldn't be influenced by the recent frustration and pressure I felt while getting it to work.

He also pointed out that despite my excellent test coverage, there may be some undiscovered edge cases lurking in that API. By waiting a little bit, I could address those edge cases in the refactor, rather than having to go back and fix them later.

I love it when Aaron throws something unexpected at me like this, and I've been pleasantly surprised in the past as to how it worked out. So, following his advice, I'm going to let it sit for two weeks and revisit it later this month, hopefully with a fresh perspective.

I will report back after the fact to share if Aaron's advice was good or not, and what I learned from the experiment.

Here to help,

Joel

P.S. Want Aaron to expand your mind too? Soak up some of that insight in the Mastering Laravel community.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.