šļø 23 May 2024Ā·š 3 min read
Why I think using spaces instead of tabs is better for writing code
Original Photo by Wilhelm Gunkel
ā ļø Warning: The opinion in this article may differ from your own. You can also share your opinion in the comment section below if you disagree with me š.
Tabs and spaces are two different characters that are rendered as whitespace on screen.
The problem is that there is no agreement on how wide a tab character must be, so some editors show it as occupying as much space as 8 spaces, some show it as occupying width of 4 and some 2, and itās also configurable.
There is a really nice article called Spaces vs. Tabs: A 20-Year Debate Reignited by Googleās Golang that shows that itās still debatable until now which one is better.
If you ask me, Iām a person who believe Spaces are better than Tabs.
Before you continue reading and think that this topic isnāt important, thereās a funny video from Sillicon Valley:
I tried to use tabs using several text editors, but I always ended up using spaces. Here are some examples of how tabs are rendered across different editors:
As you can see, the indentation is not consistent across editors. This might be a problem if youāre working in a team where each member uses different editors.
If you really care about precision, then I recommend to choose Spaces over Tabs. Now, letās try to change the indentation of the file above using Spaces as its indentation, and then see how editors will render the indentation.
As you can see, Spaces offer more consistent indentation over Tabs across editors. Thatās also why I encourage my team to update their configuration to use spaces. The easiest way to update the indentation is just simply to update the configuration on .prettierrc
file, since weāre using Prettier to format our code.
{
...
"useTabs": false
...
}
After that, make sure to turn on the āFormat on Saveā option on the text editor.
Komentar