Don’t commit the first thing that works

Tagged As:

I was working on a bug fix on our application with another fellow programmer. First we understood the root cause of the bug and what makes it to happen. All that was good. Then we thought of a solution and applied the first fix that I thought. Code works and bug is fixed, happy days. But wait.

Then I thought about the fix and it’s complexity. The bug was causing due to a list that is not getting updated and it was referring to an old memorized┬álist that we lose track once the list is created. ┬áThe first fix that we came is to have a reference to the memorized list as then we could update the memorized list. Even though this was a fixed, after looking at the Class, there was another list that is maintained to manage the same elements.

Given that we already have a working solution. I decided it is better to keep that as a backup solution and use the list that was managed by the Class as the reference. With simple line of changes we update the references to point to the list managed by the Class. Apart from fixing the buggy behavior we also managed simply our fix compared to the first approach.

So lessons learned:

Its better to get a working code quickly but also see the code and behavior in different perspectives. It will help you to find a better solution than the one you have right now.