Published on 13 June 2013.
Today’s though is about a habit that can help you enforce the boy scout rule.
The boy scout rule says that you should always leave the camp ground cleaner than you found it. Applied to software, that means always leaving the code base in a better, cleaner state than you found it.
The idea is simple, but harder to implement in practice. After you have made your change to the code base and tested it, you feel like you are done. After all, it is working. It’s easy to stop here. But if you didn’t clean up surrounding code while you implemented your change, you did not leave the code base in a cleaner state. At best, you didn’t make it worse.
To avoid that this happens, an idea would be to start with refactoring. Clean up the code you need to change before you actually make the change. That is the habit.
The refactorings doesn’t have to be big. It just has to be something that makes the code cleaner.
You always clean up the code base for every change you make, preventing it from getting worse and worse.
In the same way that writing tests first ensure that you actually write tests at all, doing refactorings firsts ensures that the code base gets cleaner.
You practice your refactoring skills continuously.
Site proudly generated by Hakyll.