The Boy Scout Principle
The Modern Developer should always leave
a Software Entity in better shape
than it was in when they entered
the Legacy Code environment
Every developer has a professional responsibility to leave the Code Base they are working in better shape when they commit the code than when they entered it.
A Code Base that has been created with Test Driven Development (TDD) makes refactoring a safe activity.
There are a Number of Safe Refactoring
that every Developer can do
Regardless of a Testable Code Base
The Boy Scout Principle applies to both Green Field projects, new projects, and Brown Field legacy projects.
Issues can exist within both types of projects
… A disciplined effort must be made
…… For Standards Compliance in Both
Safe Refactoring List
Safe refactorings using the IDE or ReSharper:
Here are Ten Code Clean ups that have minimum risk to the legacy environment:
- Remove Unused “using’ Statements
- Convert Private Data Members into Auto-Properties
- Initialize Class Level Private Properties in a Default Constructor
- Rename Bad Property Names into the Correct Class Naming Convention
- Create a Region at the bottom of the page for all Private Methods as a Helper Section
- Identify the Methods in the Class that are ONLY used in that Class and move to Helper Region
- Replace Explicit Type Names with ‘var’ to reduce the “Code Noise” in the Type
- Identify and Move the Value of ‘temp’ variables: Variables that are created and only used ONE Time. Move the variable statement to the One and Only One usage to improve performance.
- Extract Helper Methods from Large Methods and place in the Helper Region if only usable in the current Type. Extract and Move to a Common Utilities Helper Type for Code reuse by the tea. Always document Common Helper Methods in a centrally located and published Knowledge Repository.
- Extract complicated algorithms and lengthily code from Conditionals such as ‘try/catch’, nested ‘ifs’ and ‘switch’ statements. Place in the Helper Region. This will improve performance at Run-time
The Boy Scout Principle
The concept of the Boy Scout Principle is the Boy Scout Motto:
You should leave Nature’s Environment better than you found it
… By not leaving a human footprint
…… And by removing any trash that someone has left
Code refactoring to Best Practices is every developer’s responsibility!
You should leave Nature’s Environment better than you found it
… By not leaving a human footprint
…… And by removing any trash that someone has left
The Boy Scout Principle gives us the directive to help manage “Technical Debt”.
Technical Debt is when code is compromised for expediency
… At the risk of the project in the long-term
Never let obvious Code Smells stay in a solution!
Any code that does not meet the Code Standards for the Project
Any code that does not meet the Code Standards for the Project
No violation examples are required.
Violations are any non compliance with the Project Development Code Standards
The refactoring list is the examples for code refactoring
Be a Good “Code” Scout!
The Next Principle Design Series Post:
Responsibility and Dependencies Principle
Do Your Job and Your Job Only
… Let Everyone else Do Their Job
Latest posts by Brad Huett (see all)
- DevOps: A Bridge to Your DevOps Culture - March 25, 2016
- Embracing Test Driven Development (TDD) - March 25, 2016
- DevOps: Delivering Agile Projects - March 25, 2016