Latest Reading List
Cover for the book 'All Souls Lost' by Dan Moren
December 1, 2023
Latest Review
Screenshot of the opening screen of Super Mario Bros. Wonder
November 5, 2023
Latest App Update
App icon for wwriteLite
August 1, 2023
Latest Device Availability
Photo of front and back of the White Titanium iPhone 15 Pro.
December 1, 2023

My Thoughts on Tabs versus Spaces


There are two debates that will never be solved. The first is VIM vs. Emacs and the second is Tabs vs. Spaces. For the VIM vs. Emacs debate, I use VIM, only because it is the first linux-based editor I learned to use and no, I do not need to look up how to quit out of VIM (it is :q by the way, you can use :wq to write to file and quit). Instead, I would like to focus on the other eternal debate, Tabs versus Spaces. Before I delve too far into the topic, let me share some background.

Day Job

My job title at work is Developer. It has not always been this, but development is what I have been doing during my tenure there. Primarily, I create custom web applications and reports using PHP, HTML5, and CSS. Over the summer I spent some time re-writing some older code that I written. There are a variety of things to think about when making web apps, like following HTML standards, accessibility, alt on images, and the like. One aspect that is often overlooked is how the source code looks when it is viewed in an editor. Many developers overlook this aspect when it comes to web coding. Yes, the primary concern is really making sure the product works and meets standards, yet future maintainability should also be a concern particular when you need to go back and look at some code that you have not looked at in a while. You likely do not want to spend an inordinate amount of time deciphering your unformatted code.

Being able to look at the source code and have it look decent is something that I have been doing for a long time. One way that I achieve this is to line up equals signs. Here is an example of what I mean:

$short1           = "short";
$longvariablename = "long";

I could just use a single space or tab after the end of a variable name, but the code generally looks better when everything is lined up. Usually there are a number of variables within a particular function, file, or other scope of code. I would always try to line up the equals signs. This usually allows me to know what I am looking at without having to look all around the code.

However, while I was reworking the code, I came to the realization that this is somewhat wasteful. Not necessarily because of the extra keystrokes, which is part of it, but because of the amount of space that the file takes up on the drive. There is another aspect that I was thinking about as well.

Side Thought

While I was re-writing the code, there was a nagging thought in the back of my mind, the size of current webpages. With the proliferation of JavaScript-laden webpages, as well as ubiquitous tracking in general, the size of webpages have significantly increased over the past decade. Web developers often overlook

Tabs versus Spaces

My position is to use tabs whenever possible. The reason I think this is due to the size of the file. Examples are always good, so let me provide one. Say you have a file that is 2 kilobytes in size. It is small, and this file uses tabs throughout where needed. The file size is small, and generally smaller than the size of a cluster on a hard drive or SSD. Now, imagine replacing all of those tabs with four spaces. You have now quadrupled the size of the file from 2 kilobytes to 8 kilobytes. Even with this, the size of the file may still be smaller or just at the size of a single cluster on a disk.

Now, let us extrapolate that. Say for instance you have a 1 megabyte file that uses tabs and you replace each tab with four spaces. The file size has again quadrupled but now it is four megabytes in size. Even if the file is only called once in a while, it is still a rather large file. Let us extrapolate this further. Imagine the file is called 1000 times per day and at 4MB, that is now 4GB worth of bandwidth used. If you are on an internal network that may not be a concern, but on the internet it can become one.


I should clarify, the above example is only meant for interpreted code, not complied code. For the source of compiled code, it may not make a difference. It should also be noted that you could use a strip-whitespace function for some languages, however, depending on the language this may result in the script being misinterpreted.

I know some language style guides indicate what should be used, where most indicate spaces. If I was going to release something as open source and to be used by a wide variety of individuals I would likely follow the style guide of the language, but for personal projects, I will continue to use tabs.

Closing Thoughts

Maybe it is just my thinking, but reducing the overall code size of a project is a good thing, particularly if it is a web-based application. Not only will this save on storage space, but it will also save on the bandwidth consumed by users who are often saddled with a bandwidth cap. While I can understand the need for following a style guide, it is also possible that the time the style guide was written that some considerations were not taken into account. Lastly, do not do what the top image does, that is just wrong and is prone to errors.