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.

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.

Just a short comparison between Emacs and Atom Text Editor. Emacs is a very old text editor; Atom is modern. Both are highly customisable. Atom has a lot of packages available; Emacs has more than enough packages available. But I choose Emacs over modern editor like Atom, because Emacs has various powerful modes available. It is not only an editor, but can also be a debugger, or even IDE. Based on my experience, Emacs auto-indentation on the complex HTML with JavaScript and CSS works better than Atom.

As a result, I choose space indentation over tab indentation, as it is more consistent and text editor independent.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s