Tabs vs Spaces. The most significant computer problem
TL;DR: Don't mix indentation styles
-
Readability
-
Code consistency
-
Standards violation
-
Choose one of them
-
Stick to it
-
Enforce it with code standards tests
-
Share the rules on all the codebase
-
Use an IDE like VSCode or WebStorm that doesn't include tabs at all.
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.
function add(x, y) {
// --->..return x + y;
return x + y;
}
function main() {
// --->var x = 5,
// --->....y = 7;
var x = 5,
y = 7;
}
function add(x, y) {
// --->return x + y;
return x + y;
}
[X] Automatic
Any parser can enforce this rule.
Some languages like Python consider indent as part of the syntax.
In these languages, indentation is not accidental since it changes code semantics.
- Code Standards
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.
Code Smell 48 - Code Without Standards
Code Smells are just my opinion.
Whatever the device you use for getting your information out, it should be the same information.
Tim Berners-Lee
Software Engineering Great Quotes
This article is part of the CodeSmell Series.