The Boy Scout Rule
I am reading a book titled "Clean Code". It was written by Robert C. Martin (aka Uncle Bob).
One thing I like about reading books like these is that they put words on things that I do or think. They express them in a way I did not think about.
One thing that I have been doing naturally is to follow the Boy Scout Rule. I did not call it that. I did not even know I could give it a name. I did it because I thought it was the right thing to do. Uncle Bob gave it a name and explained it well.
When I work on code, I open up a file and sometimes see a mess. The file's formatting is wrong. The class is just one big method of 100 lines.
Then, if I have trouble understanding the code, I refactor it a bit.
But... I could break the code. Introduce new bugs. So how can I clean it up and be confident it still works? Even before I clean it up, I create unit tests (if none existed). If they existed, I run them to make sure they run now (before I make any changes).
The Boy Scout Rule (or Law) is to never leave a camp without first making sure it is cleaner than it was when I got there.
Why do you think we MUST follow this rule? Why would we (programmers) care?
Because code is like an apple. It rots. It degrade. And the more bad apples there are around it, the faster it will degrade.
You don't want your code to become a mess, do you? I hope you don't!
So, in your quest to become a better, professional programmer... why don't you start (or continue) to follow this rule?!? :) I dare you! :-D
Make a Payment to Christian Roy