# Code Smell 164 - Mixed Indentations

> TL;DR: Don't mix indentation styles

# Problems

- Readability

- Code consistency

- Standards violation

# Solutions

1. Choose one of them

2. Stick to it

3. Enforce it with code standards tests

4. Share the rules on all the codebase

5. Use an IDE like VS Code or WebStorm that doesn't include tabs at all.

# Context

Whenever I publish an article many people don't care about the sample intent and rush to point at indentation mistakes.

Choosing one standard over the other will be a great solution.

Spaces always count as one.

Tabs can count as many different options.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/17de024e249327b44a614f30e4961d94)
```javascript
function add(x, y) {
// --->..return x + y;

      return x + y;
}

function main() {
// --->var x = 5,
// --->....y = 7;

    var x = 5,
        y = 7;
}
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/49bfb99979315a69bfe809afb0ae2158)
```javascript
function add(x, y) {
// --->return x + y;
    return x + y;
}
```

# Detection

[X] Automatic 

Any parser can enforce this rule.

# Exceptions

Some languages like Python consider indent as part of the syntax.

In these languages, indentation is not accidental since it changes code semantics.

# Tags

- Code Standards

# Conclusion

There's been so much debate on this subject.

The smell is related to mixing them, not about using one instead of another.

Some IDEs automatically convert one convention to the other one.

# Relations

%[https://maximilianocontieri.com/code-smell-48-code-without-standards]

# More Info

- [ES Lint](https://eslint.org/docs/latest/rules/no-mixed-spaces-and-tabs)

# Disclaimer

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

* * *

![indentation joke](https://cdn.hashnode.com/res/hashnode/image/upload/v1663723654976/gTJCui71h.jpg)

> Whatever the device you use for getting your information out, it should be the same information.

_Tim Berners-Lee_

%[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]
