The power of starting over 🔄
Last week, I found myself stuck in a “code hole”. To paraphrase James Kerr:
You know you’re in a code hole when you have 100+ type errors to fix, tests are not passing, you are “refactoring” something distantly related to what you set out to do, and the diff from main is so big the PR is unreviewable.
For more than one hour, I had been “almost there”, but just could not seem to get everything working.
Sometimes you truly are “almost there” and the right decision is to power through. Other times, you’re just digging deeper. My gut was telling me the latter.
When I get stuck like this, it is almost always because I tried to make several changes at once. One planned change led to one or more unplanned changes.1 IÂ forgot to do depth-first development, falling into the “breadth-first development” trap. “It is so easy”, the sirens sing to me, “just improve things as you go along”.
In this case, I eventually decided to start over—to revert all my changes and reimplement the feature from scratch. If you’re not used to this, it may feel like a waste. You have already written so much and are “almost there”. In my experience, the waste is not that big. After all, the previous code was bad enough that you decided to start over. If you want to play it safe, you can always commit the previous attempt before reverting.
The key to starting over is that while you throw away the code, you keep the lessons. You can make a second attempt armed with what you learned from the first one still fresh in mind. You also get a new chance to practice depth-first development—to perform each change as a distinct step with a clean commit.
Starting over isn’t failure—it’s a powerful development skill.
-
If you find yourself making lots of unplanned changes, it might be time to play“yak or squirrel?” ↩︎