The Boy Scout Software Development Principle
Leave your code in a better state than you find it, in every single pull request
Join the DZone community and get the full member experience.
Join For FreeBoy scouts have an easily understood philosophy, which is that they should always leave their campsites in a better condition than the state which they found it in. Cleaning away one piece of garbage each, or something equivalent, creates a situation where a visit from a boy scout group, becomes a great experience for everybody else. Developers can learn a lot from this philosophy.
Every single time you create a pull request, the code you commit should "pick up one piece of garbage", by refactoring it somehow, making it more easily read, and/or performing better somehow. If you make a habit out of this, then over time your codebase will slowly become better.
Pick up other people's garbage
If you do it, and you instruct your developers to also do it, after a while everybody will do it. Below is an example to get you started.
void Foo(int val)
{
if (val != 0)
{
/* ... Do stuff with val ... */
}
else
{
throw new ArgumentException("Val is 0");
}
}
For the seasoned developer, spotting the garbage in the above method is fairly simple. Hint: Invert your if! Let me show you a simpler version, with less garbage, to illustrate my point.
xxxxxxxxxx
void Foo(int val)
{
if (val == 0)
throw new ArgumentException("Val is 0");
/* ... Do stuff with val ... */
}
By simplifying and inverting our above if statement, we reduced the size of the code from 11 lines to 6 lines. 50% of the code gone! And we did it without changing any logic what so ever. The code is more easily read, which makes it more easily maintained, and the method as a whole more easily fits into a single screen, without scrolling, making it a much more pleasant experience to go back to it 6 months down the road, to add another feature to it ...
I could add more to this article - However, that would only add garbage to it - So I'll leave it here for now :)
Opinions expressed by DZone contributors are their own.
Comments