1

I am working with Asp.net mvc web application but my friend saying work with clean code most of time saying boy scout rules apply for clean code

anyone explain . shortest and suiter way

thank you

Quiet Islet
  • 536
  • 1
  • 8
  • 28
  • 1
    I see two problems with this. 1) You could introduce an additional bug along with your new enhancement (now you have two bugs in JIRA). 2) It can lead to more SCM source code conflicts with concurrent edits with your peers during checkin if you go rampant with say _Resharper Code Cleanup_ (been there done that) –  May 19 '16 at 05:33
  • @FerdinandSwaters thanks for your suggest.I would be glad if you explain shortest and suiter way – Quiet Islet May 19 '16 at 05:43
  • 1
    Perhaps you could ask your friend what they mean? There are plenty of 'boy scout rules'. I would imagine they mean to leave it tidier than when you arrived? But who knows, they could mean anything. You should ask them. – Rob May 19 '16 at 05:51
  • @Rob thanks for your suggest. he provide me a book . he is a marketing person . may be he heard someone about this . – Quiet Islet May 19 '16 at 06:02

2 Answers2

7

The Boy Scout Rule

It's not enough to write the code well. The code has to be kept clean over time. We've all seen code rot and degrade as time passes, so we must take an active role in preventing this degradation.

The Boy Scouts of America have a simple rule that we can apply to our profession:

Leave the campground cleaner than you found it - chapter 5

If we all returned our code a little cleaner than when we checked it out, the code simply could not rot. The cleanup doesn't have to be something big - change one variable name for the better, break up one function that's a little too large, eliminate one small bit of duplication, clean up one composite if statement, etc.

Can you imagine working on a project where the code simply got better as time passed? Do you believe that any other option is professional? Indeed, isn't continuous improvement an intrinsic part of professionalism?

You can also check this out: What was the strangest coding standard rule that you were forced to follow?

Community
  • 1
  • 1
Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73
1

The boy scout rule says that you should leave the code at least as "clean" as you found it (or for the ambitious: even a bit cleaner than you found it). That means when you change a method due to a change request, you should improve the maintainability/quality of that method along the way. That could, for example, mean to improve the method's name or the names of the variables inside. The advantage is that you need to understand the method in any way (because of the change request) and that it will be tested as you will mostly likely test the change anyway. The overhead for quality improvement is therefore almost 0. Applying the boy scout rule is a very good measure to steadily improve the code quality with low risk. It also allows you to concentrate on the code that you are actually changing while not spending hours improving code you never touch anyway.

Nils Göde
  • 545
  • 3
  • 9