Tuesday, August 21, 2018

The Coder's Code

The Boy Scout Rule states, roughly, as follows:
Always leave the trail better than you found it.
I think we can translate this to a Coder's Code. It can even be relaxed a little and still create the same effect:
Always leave the code as good as you found it or better. 
Think about the pressure that puts on code. If you take making the code worse off the table, you're left with making it better or keeping it the same. Many changes are likely to affect the quality of some code. So, necessarily, code will start to trend better when a rule like this is in force.

I'm certainly not the first one to note that the Boy Scout Rule also applies to code. It's not even the first way I heard the idea expressed.

My first introduction to this as an explicit principle, rather than what everyone should just intuitively know, was when a friend of mine said we should have a coder's equivalent to the Hippocratic Oath. That oath is long, actually, and my friend really just wanted to extract the one most famous clause:
Primum non nocere. (First, to do no harm)
I'm sure there are other ways to express the concept, too.

It doesn't matter how you express it. It doesn't even matter that you express it.

All that matters is that you stop hurting the code you work with and, thus, stop hurting yourself and your coworkers.