DEV Community

Pandiyan Murugan
Pandiyan Murugan

Posted on

Tabs vs Spaces?

What're the real technical key aspects that need to be considered before deciding or coming to a conclusion of battle of Tabs vs Spaces?

Top comments (34)

Collapse
 
pavelloz profile image
Paweł Kowalski

Its 2020, stop talking about it and start using editorconfig.

Collapse
 
kylefilegriffin profile image
Kyle Griffin

Yep. Tabs is the correct answer so people need to stop.

Collapse
 
pandiyancool profile image
Pandiyan Murugan

Quick decision!!!

Collapse
 
pchinery profile image
Philip

You are absolutely right. The question is though: should we put tabs or spaces in the config? ;-)

Collapse
 
pavelloz profile image
Paweł Kowalski

Whatever you feel like it. It doesnt matter. And if project already has one, forget about it and do your job.

Collapse
 
pandiyancool profile image
Pandiyan Murugan

I was about reply the same :p

Using config is fine.!

Collapse
 
pandiyancool profile image
Pandiyan Murugan

I'm collaborating with different projects.

I'm using the tabs in some project and space in some project

Editor config saving me daily. Without mixing up I'm using target things properly.

Collapse
 
lionelgaillard profile image
Lionel Gaillard

I use spaces because I stick to conventions, but I would prefer tabs because:

  • That the purpose of tabs.
  • Count as one character.
  • Accessibility: IDEs can display tabs with selected width.

I read a post about a guy with a severe sight issue, who, to be able to code, had a very large font size configured in his IDE.
But at this font size, four spaces are huge, and he had to scroll horizontally all the time.
So each time he edited a file, he changed spaces to tabs (which were displayed with a width of one space), and changed back tabs to spaces before to commit !

For most of us, the battle of tabs vs spaces is totally vain.
For some of us, it can change their everyday experience.

Collapse
 
louy2 profile image
Yufan Lou

Thank you so much for bringing this reason to my attention.

I will use tabs for all my indentation going forward.

Collapse
 
pandiyancool profile image
Pandiyan Murugan

I love tabs

Collapse
 
alexdesousa profile image
Alex de Sousa

I use spaces, but I've heard a compelling argument favouring tabs.

Tab width can be customized easily in any editor. This is useful for people with visual impairments:

If someone needs larger fonts, then, to fit relevant code in the screen, reducing the tab width might help. With spaces, this kind of customization is hard to accomplish.

This same argument works for 80 character lines.

In the end, I don't really care. I would gladly switch to tabs if that helps people with visual impairments to contribute to open source or private code bases. I only care about consistency.

Collapse
 
rhymes profile image
rhymes

Use Go so you don't have to decide 😂

The formatting tool uses tabs and that's the standard

I use spaces in all the other languages but I'm super okay with Go which decided to kill this conversation from day 1 😂

Collapse
 
pandiyancool profile image
Pandiyan Murugan

GOD MODE

 
abdisalan_js profile image
Abdisalan

Sorry for the confusion, when I say 4 spaces vs 2 spaces, I mean the tab character \t displays as that number of spaces.

There is no conversion, the linter keeps everything as tabs so there's to worry of mixing tabs and spaces and everyone can display their indentation how they like.

I think this entire debate isn't really worth discussing given the current state of linting/developer tooling.

Collapse
 
abdisalan_js profile image
Abdisalan

IDEs showing tabs how I like is a good thing! If the code base has 2 space indentation, why should I be forced to view my code that way if my IDE can just display it with 4 spaces and commit to GitHub with 2 spaces?

Collapse
 
avalander profile image
Avalander • Edited

I don't think there's any technical aspect to consider. It boils down to preference mostly. Sure, arguments can be done for both sides, like tabs being awesome because everyone can configure the desired tab length in their code editor, or horrible because they show as eight spaces in GitHub pull-requests. But I have never heard an argument for either side that had any real technical implications.

Collapse
 
pandiyancool profile image
Pandiyan Murugan

Thanks

Collapse
 
leighshammer profile image
Leigh Barnes

It really dosnt matter, as long as a code base is maintained and standardized.
There is literally nothing worse than seeing a Tabs Vs Spaces comment on a PR, I would hate to know how much time effort and frustration and company times has been lost to this argument.

Collapse
 
pandiyancool profile image
Pandiyan Murugan • Edited
           Hmmm....

Added some spaces here

Collapse
 
jonashdown profile image
Jon Ashdown

The issue arose from a number of factors, but primarily boils down to the visual differences which occur in badly configured IDEs

I personally use the tab key to indent, but configure my IDE based on the linting rules of the project I am working on.

docs.google.com/presentation/d/1Kk...

Collapse
 
pandiyancool profile image
Pandiyan Murugan

Thank you

Collapse
 
alvaromontoro profile image
Alvaro Montoro

3 reactions and 21 comments... You knew what you were getting into 😋

Collapse
 
pandiyancool profile image
Pandiyan Murugan

Yes....