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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • The SDLC After AI
  • You Don’t Need To Be a Manager To Lead: Why Leadership Matters for Software Engineers
  • 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

Trending

  • Who Should Grade Your AI? Rules vs LLM Judges vs Humans
  • The Context Window Trap: Why More Context Doesn’t Mean Better AI
  • AI Coding Agent Guardrails: Finding Gaps in Tool Permissions
  • Java 8 Optional - Avoid Null and NullPointerException Altogether - and Keep It Pretty

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

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
DZone Core CORE ·
Aug. 21, 20 · Opinion
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
10.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • The SDLC After AI
  • You Don’t Need To Be a Manager To Lead: Why Leadership Matters for Software Engineers
  • 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

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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