I was using tab for indentation in coding, instead of spaces. Because I feel that one byte of tab is better than four bytes of space. It produces smaller file size.
However, the problems become prominent in the following circumstances.
- Viewing different languages may require different indentation width. XML and HTML may use 2 characters width, other languages may use 4 characters width. Changing the tab width from the setting frequently is inconvenient.
- Editing source code with different developers and using different text editors will produce source code with both tab and space indentation. As a result, the indentation becomes inconsistent.
- Emacs problem. If the Emacs tab width is set to 8 characters, but the source code indentation is 4, this produces both tab and space indentation at the same line, for example, 3 indents (12 characters width) produce 1 tab with 4 spaces. Oh dear, I always show the whitespace and tab marks in the editor. The ugliness disturbs me.
- Git diff view. If using Git GUI, it will highlight the tab indentation when the pervious line is a space indentation.
So, in the cases above, space indentation becomes handy. Though different developers use different text editor may produce different width of space indentation, with space indentation will produce better output than tab indentation.
But not all text editors support auto-indent feature, and not all text editors support tab to space indentation. So, I have to choose the text editor that meets my need.
I use jEdit and recently use Emacs. jEdit allows to convert the tab to space easily. But jEdit does not have the fixed indentation like Emacs. Emacs has the “major modes”, based on the major modes, the source codes are syntax highlighted differently and the indentation will be arranged differently.
As a result, I choose space indentation over tab indentation, as it is more consistent and text editor independent.