Posts
read more
Tab vs space
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.