Always leave the campground cleaner than you found it.” If you find a mess on the ground, you clean it up regardless of who might have made it.
TL;DR: Follow Uncle Bob's boy scout rule.
Problems
Readability
Maintainability
Solutions
Leave the code better
Change it
Context
We read code many more times than we write.
We must take ownership of code with errors and leave it better.
Sample Code
Wrong
int mult(int a,int other)
{ int prod
prod= 0;
for(int i=0;i<other ;i++)
prod+= a ;
return prod;
}
// Formatting, naming, assignment and standards inconsistent
Right
int multiply(int firstMultiplier, int secondMultiplier) {
int product = 0;
for(int currentIndex=0; currentIndex<secondMultiplier; currentIndex++) {
product += firstMultiplier;
}
return product;
}
// or just multiply them :)
Detection
[X] Semi-Automatic
We can use other code smell detectors and leave the code in a better shape.
Tags
- Standards
Conclusion
We must follow the Boy Scout rule and leave the code better.
Relations
Code Smell 164 - Mixed Indentations
Maxi Contieri ・ Sep 21 '22
Disclaimer
Code Smells are just my opinion.
Credits
Photo by Pawel Czerwinski on Unsplash
One broken window, left unrepaired, instills in the inhabitants of the building a sense of abandonment. People start littering. Graffiti appears. Serious structural damage begins. In a relatively short span of time, the building becomes damaged
Andy Hunt
Software Engineering Great Quotes
Maxi Contieri ・ Dec 28 '20
This article is part of the CodeSmell Series.
Top comments (0)