Tabs Are Better Than Spaces
In code, TABS should be used to indent blocks.
SPACES should be used for vertical alignment.
TABS + SPACES is whitespace Nirvana.
if (condition) {
/* This block is indented with tab */
/* Vertical alignment is done with spaces */
x = 123456.789;
y = 12.345;
/* Spaces can be used to line up multi-line expressions */
if (one_condition ||
another_condition ||
third_condition) {
/* This is another indented block, with tab */
log("Nirvana");
}
}
The benefits of using TAB for indenting are obvious:
- Horizontal whitespace is left as a display setting, configurable by the developer. Some may prefer tab size 2. Some may prefer 8. They both get to view the code in the way that is easiest for them to read.
- Vertical alignment of code, comments, and syntax within a block can be done with spaces. The alignment remains correct regardless of the user's tab size.
- The semantic meaning of a tab (code block indent) is maintained.
- All IDE's support tabs correctly.
- Fewer bytes in the file.
Using TABS for indent and SPACES for alignment within blocks gives you the best of both worlds. Developers retain control of the display of their code, while alignment and layout of the code itself remains stable.
Conclusion: Tabs Are Better Than Spaces