Packetizer Logo
 

Writing Code for the Next Person

By: Paul E. Jones

Tabs vs. Spaces

Way back at the beginning — long before I or most of you reading this were born — tab characters were used as a means of indenting code on the screen. The reason is that a tab character takes one byte of memory, whereas each space takes a byte of memory. The tab was defined as indenting eight character positions, so using spaces to indent vs. a single tab character was considered to be a pragmatic choice in order to preserve previous storage and memory.

As the years passed, people began to transition from using the tab character to using spaces. As mentioned above, the default indentation width moved from eight character positions to four almost universally. For a while, though, there were some who firmly clung to the use of the tab character even though there really was no reason. After all, storage space and RAM became relatively cheap. In fact, the code is usually insignificant in size relative to a computer's storage or RAM.

One argument I was given for using tabs is that it provides flexibility for the user to select his or her preferred tab width. I hear the argument, but that generally does not work out well. For example, a function might be written with one or more parameters after the opening parentheses with additional parameters on the next line. Depending on the coding style, those might be indented slightly or aligned with the open parentheses. In the latter case, changing the tab width will break that alignment. The same issue arises when having in-line comments that appear on a specific column for beauty (e.g., column 49). Changing the tab width pushes or pulls those comments out of alignment.

The practice of using tab characters needs to end. One of the really annoying thing about code with tabs in it is when somebody starts working on that code without realizing it used tabs. It results in an absolute mess. Fortunately, tools like vim can make it trivial to remove or add tabs, but at this point there really is no good reason to use tabs just to avoid the problem in the first place.