DEV Community

Cover image for Tabs v. Spaces: Let’s decide this

Tabs v. Spaces: Let’s decide this

Nočnica Mellifera on April 03, 2020

Do you use tabs or spaces? Why? Let me know in the comments!

Collapse
 
craigmc08 profile image
Craig McIlwrath

I haven't seen the argument of accessibility tossed around here yet. I saw it a while back and it's stuck with me. Tabs have configurable width, spaces do not. If some people need deeper tabs, they can't do that with spaces.

Personally, I use spaces. I think that's because a lot of people use spaces. I'm not opposed to using tabs (they might even be more convenient for deletion using backspace/delete key).

Collapse
 
gregfletcher profile image
Greg Fletcher • Edited

Having both isn't necessary. We only need one. In my opinion, if we had to get remove one, it would be tabs. Spaces can't be removed so they stay. It reminds me of null and undefined in JavaScript. Two different things to do one job. It's unnecessary and can lead to bugs. Best to only have one. That's what I think 🙃

Collapse
 
nocnica profile image
Nočnica Mellifera

I like that you only will accept total victory: in the war of spaces versus tabs, tabs must be completely annihilated

Collapse
 
sergix profile image
Peyton McGinnis
Collapse
 
silvether profile image
silvether

Its also possible for users to configure their editor/ide to accept a tab character as a series of individual spaces. I can't understand why more folks don't do this. They can still press their single button, but have the precision of the spaces in play.

VIM:

config file: ~/.vimrc

set tabstop=4 " The width of a TAB is set to 4.
" Still it is a \t. It is just that
" Vim will interpret it to be having
" a width of 4.

set shiftwidth=4 " Indents will have a width of 4

set softtabstop=4 " Sets the number of columns for a TAB

set expandtab " Expand TABs to spaces

Collapse
 
sergix profile image
Peyton McGinnis

Yeah, in VSCode my tab key = 2 spaces. I don't use vim as much but I'll be adding that to my config. 👍🏼

Collapse
 
iamscr1pty profile image
Biswajit Pramanik

Didnt know that, saved me some effort😋

Collapse
 
sduduzog profile image
Sdu

Spaces pretending to be tabs. I'm done.

Collapse
 
gabrielecimato profile image
Gabriele Cimato

I feel like nowadays for this argument it's hard to take the tabs side. The advantage could have been just faster indentation but now editors convert your tabs into spaces automatically so there's really no reason at all to use tabs! Fast indentation + same interpretation across any editor = WIN! 🏆

Collapse
 
sigmapie8 profile image
Manav

Tabs that gets saved as spaces.

Collapse
 
codemouse92 profile image
Jason C. McDonald

Let's not "decide"! Use what works for your project. One project needs tabs; another needs spaces. It depends on the project goals, the development tools, and the team's needs. To make a declaration that one is objectively and unilaterally better than the other is to assume one knows all the possible projects that could ever exist.

Collapse
 
nelsonmestevao profile image
Nelson Estevão

We can not forget that Makefiles need tabs! I use spaces everywhere but I need to have my editor configured to use tabs when I am editing a Makefile.

I use both and that's the reason. Honestly, I always use the formatter in the end. So, do you remember go fmt? Yap, it converts all my spaces to tabs again.

Collapse
 
iamscr1pty profile image
Biswajit Pramanik

In different IDEs tabs are interpreted differently but spaces aren't , so its safe to use spaces.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Trend to switch from monospace to ligature might also result in tab preference.

2-4 spaces are only good in monospace fonts.

But we cannot use ligature everywhere, unlike monospace where can find in most places, so spaces will still live.

Collapse
 
cescquintero profile image
Francisco Quintero 🇨🇴

editorconfig.org/ + plugins for text editors:

indentation: spaces
size: 2

Collapse
 
therealkevinard profile image
Kevin Ard • Edited

Spaces, but the golden ratio expression of depth.

spaces = ceiling(IndentLevel * 1.615)

Collapse
 
jarodpeachey profile image
Jarod Peachey

Tabs, because instead of clicking the spacebar 2-5 times, depending on your indentation, you customize the tab width and click it once.

Collapse
 
silvether profile image
silvether

You can set an IDE to use the TAB button to place spaces. Takes 5 minutes and you now have the precision of spaces. I posted a quick 4 line above you can add to a VIM config. Give it a try.

Collapse
 
jep profile image
Jim

I prefer the granularity of spaces, but the efficiency of tabs. So the obvious compromise is to configure your editor so that a tab generates a tab's length of spaces.

Collapse
 
dendihandian profile image
Dendi Handian

I use tabs that produce 4 or 2 spaces.

Collapse
 
pavelloz profile image
Paweł Kowalski

Two tabs. One tab = three spaces.

Collapse
 
elmuerte profile image
Michiel Hendriks • Edited

Tabs, because it's more friendly to people with visual disabilities.

But I use whatever the projects uses. Code style is the law.