# Code Smell 173 - Broken Windows

> 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

[Gist Url]: # (https://gist.github.com/mcsee/5577d55a7a059073137b7d892b218e80)
```c
    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

[Gist Url]: # (https://gist.github.com/mcsee/952f2de180ccdbe8bb73f7dfac162fe5)
```c
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

%[https://maximilianocontieri.com/code-smell-164-mixed-indentations]

%[https://maximilianocontieri.com/code-smell-159-mixedcase]

# Disclaimer

Code Smells are just my [opinion](https://maximilianocontieri.com/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned).

# Credits

Photo by [Pawel Czerwinski](https://unsplash.com/@pawel_czerwinski) on [Unsplash](https://unsplash.com/s/photos/windows-broken)  

* * *

> 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_
 
%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]
