Code Smell 174 — Broken Windows

Code Smell 173 — Broken WindowsAlways 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.ProblemsReadabilityMaintainabilitySol…


This content originally appeared on Level Up Coding - Medium and was authored by Maximiliano Contieri

Code Smell 173 — Broken Windows

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

  1. Leave the code better
  2. 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

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

This article is part of the CodeSmell Series.

How to Find the Stinky parts of your Code


Code Smell 174 — Broken Windows was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Maximiliano Contieri


Print Share Comment Cite Upload Translate Updates
APA

Maximiliano Contieri | Sciencx (2022-10-27T23:19:00+00:00) Code Smell 174 — Broken Windows. Retrieved from https://www.scien.cx/2022/10/27/code-smell-174-broken-windows/

MLA
" » Code Smell 174 — Broken Windows." Maximiliano Contieri | Sciencx - Thursday October 27, 2022, https://www.scien.cx/2022/10/27/code-smell-174-broken-windows/
HARVARD
Maximiliano Contieri | Sciencx Thursday October 27, 2022 » Code Smell 174 — Broken Windows., viewed ,<https://www.scien.cx/2022/10/27/code-smell-174-broken-windows/>
VANCOUVER
Maximiliano Contieri | Sciencx - » Code Smell 174 — Broken Windows. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/27/code-smell-174-broken-windows/
CHICAGO
" » Code Smell 174 — Broken Windows." Maximiliano Contieri | Sciencx - Accessed . https://www.scien.cx/2022/10/27/code-smell-174-broken-windows/
IEEE
" » Code Smell 174 — Broken Windows." Maximiliano Contieri | Sciencx [Online]. Available: https://www.scien.cx/2022/10/27/code-smell-174-broken-windows/. [Accessed: ]
rf:citation
» Code Smell 174 — Broken Windows | Maximiliano Contieri | Sciencx | https://www.scien.cx/2022/10/27/code-smell-174-broken-windows/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.