Skip to content

The boy scout rule

 Published on 25th January 2014

Keeping a clean codebase is an ongoing process. We try our best to do things well to begin with, but we're always going to come across things that could be improved.


Refactoring is a great way to tidy up your codebase, but it's highly unlikely you’ll have scheduled time to do this. The best method I’ve found is the Boy Scout rule.

Always leave the campground cleaner than you found it.

This can be directly translated to Always leave the codebase cleaner that you found it. So every time you work on a module, leave it in a better state than when found it.

Every day I touch multiple files from various parts of our codebase. For the past few weeks, every time I’m in one of those files, I try to find something I can improve.

The kind of things I’m looking for could be anything from improper indentation, mixed single and double quotes, obvious duplication, or maybe a function that I wrote six months ago that I now know could be more efficient or modular.

For the good of the team

What would happen if we all started cleaning up as we go?

I think if we all followed that simple rule, we’d see the end of the relentless deterioration of our software systems. Instead, our systems would gradually get better and better as they evolved. We’d also see teams caring for the system as a whole, rather than just individuals caring for their own small little part.

Uncle Bob

Cleaning up as you go is not only beneficial to you, but also to your fellow team mates. By making the codebase cleaner and easier to maintain, you make everyones life easier.

There is one caveat here. I’m not going to completely rewrite someone else’s code without involving them. There are many reasons for this, including the fact that I don't necessarily understand the intent of that code.

It’s important to involve your team mates when making changes to their work. There would have been good reasons for using the approach they took. If there is a way it can be improved, you should pair, so you both understand what is going on.

Start small

If you’ve never worked in this way before, I highly recommend that you give it a try. Remember, you don’t have tidy up your entire codebase. Just make something a little bit better than it was before.