Should You Use Tabs of Spaces When Formatting Your Code?

The not so Controversial Code Formatting Controversy

Dan Spedaliere

By Dan Spedaliere
Production Director

The not so Controversial Code Formatting Controversy

Tabs vs Spaces

For all the fans of the HBO series Silicon Valley, I did a quick experiment. Before I get into the actual experiment, below is a link to the very NSFW video clip from the most recent episode of Silicon Valley which inspired the experiment.

Tabs vs. Sapces

The Experiment!

In the screen shot below you’ll see two instances of notepad displaying the exact same four lines of Lorem ipsum. What I did was break each sentence into its own line. In the top file – named tabs – I used the Tab key to create white space before each sentence. The white space created with each Tab is equivalent to 8 individual spaces.  In the file on the bottom I use the aforementioned 8 individual spaces to create the same amount of white space before each line.

tabs vs spaces file size

The Verdict!

The file which used a single Tab before each sentence to create white space is 28 bytes smaller then the file which used spaces. While 28 bytes doesn’t seem like anything to flinch at, this difference in file size was accomplished formatting only four sentences. Think about the reduction in application size in you only used Tabs to format all of your files! While I’ve always been a fan of Tabs for no particular reason, after this experiment I see no reason to switch it up.

Article’s Additional Tags: