DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Stop Using the ATM-Didn’t-Kill-Jobs Story to Reassure Developers About AI
  • The 7 Pillars of Meeting Design: Transforming Expensive Conversations into Decision Assets
  • How AI Is Transforming Software Engineering and How Developers Can Take Advantage
  • When AI Crashes: Classifying Failure Modes in Safety-Critical Software

Trending

  • When Search Started Breaking at Scale: How We Chose the Right Search Engine
  • Comparing Top Gen AI Frameworks for Java in 2026
  • Setting Up Claude Code With Ollama: A Guide
  • Liquibase: Database Change Management and Automated Deployments

The Boy Scout Software Development Principle

Leave your code in a better state than you find it, in every single pull request

By 
Thomas Hansen user avatar
Thomas Hansen
DZone Core CORE ·
Aug. 21, 20 · Opinion
Likes (15)
Comment
Save
Tweet
Share
9.8K Views

Join the DZone community and get the full member experience.

Join For Free

Boy 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.

C#
 




x
10


 
1
void Foo(int val)
2
{
3
  if (val != 0)
4
  {
5
    /* ... Do stuff with val ... */
6
  }
7
  else
8
  {
9
    throw new ArgumentException("Val is 0");
10
  }
11
}


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.

C#
 




xxxxxxxxxx
1


 
1
void Foo(int val)
2
{
3
  if (val == 0)
4
    throw new ArgumentException("Val is 0");
5
  /* ... Do stuff with val ... */
6
}


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 :)

Software development

Opinions expressed by DZone contributors are their own.

Related

  • Stop Using the ATM-Didn’t-Kill-Jobs Story to Reassure Developers About AI
  • The 7 Pillars of Meeting Design: Transforming Expensive Conversations into Decision Assets
  • How AI Is Transforming Software Engineering and How Developers Can Take Advantage
  • When AI Crashes: Classifying Failure Modes in Safety-Critical Software

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook