# Code Smell 42 - Warnings/Strict Mode Off

> TL;DR: don't ignore warnings and alarms. You will regret it.

# Problems

- Missed Errors

- Ripple Effect

- Fail Fast

# Solutions

1. Enable all warnings

2. Enable preconditions and assertions in production.

3. [Fail fast](https://maximilianocontieri.com/fail-fast)

4. [Design by contract](https://en.wikipedia.org/wiki/Design_by_contract)

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/d4f19089543214fbc677a846967cb501)
```javascript
array = [];
console.log(array['1'])
//undefined but keep going on

hiddenGlobal = "I am a global"

console.log(hiddenGlobal)
//  I'm a global
``` 

## Right

[Gist Url]: # (https://gist.github.com/mcsee/4523879f8fd11134654d4683b5c68ceb)
```javascript
array = [];
console.log(array['1'])
//Index Error

noGlobal = "I am not a global"

console.log(noGlobal)
// ReferenceError

var noGlobal = "I am not a global"

console.log(noGlobal)
// I am not a global
``` 

# Detection

Most languages have warning levels. We should turn most of them *ON*.

We should run linters to statically analyze our code for potential problems.

 # Tags

- Fail Fast

# Conclusion

If we ignore warnings and code moves on sooner or later it will fail.

If the software fails *later* it will be very difficult for us to find root cause. 

Defect will likely be near first warning and far away from the crash.

If we follow the *Broken Windows Theory*, we should not tolerate any warnings, so a new issue will not pass unnoticed on a sea of *tolerated* warnings.

# Relations

%[https://maximilianocontieri.com/code-smell-19-optional-arguments]

%[https://maximilianocontieri.com/code-smell-12-null] 

# More info

%[https://maximilianocontieri.com/fail-fast] 

%[https://blog.rahulism.co/use-strict-in-javascript]

# Credits

Photo by <a href="https://unsplash.com/@electronicsocks">Noah Dominic Silvio</a> on <a href="https://unsplash.com/s/photos/traffic-light">Unsplash</a>

* * *

> One man's crappy software is another man's full time job.     

_Jessica Gaston_
 
* * *
 
%[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]
