DEV Community

. --. ..- ... ..
. --. ..- ... ..

Posted on

Tabs vs. Spaces

comment tabs or spaces !!!! and why.....

Latest comments (16)

Collapse
 
aurelkurtula profile image
aurel kurtula

Do you ever find something really interesting but at the same time can't be bothered researching?

For example "why is the tower of pisa bent?", I find it so fascinating but not enough to search it on google!

Equally fascinating is why on earth is this a topic of discussion. One tab vs 4 space!

I must be wrong but I can't be bothered researching it

:)

Collapse
 
val_baca profile image
Valentin Baca
  1. Whatever the existing style guide uses.
  2. If no style guide exists, spaces because it keeps the whitespace simple.

You're already using spaces in your code, say:

Thing thingOne = new Thing(); // Spaces in between each item
    Thing thingOne... // and spaces before!

So why introduce another whitespace character? Now deleting a whitespace has different effects depending on where it is. Now I have to :set list to see whitespace to be able to edit a file and know what's going to happen.

[tab][tab]Thing[space]thingOne[space]...

Btw, no one is hitting their space bar 4 or 8 times. You hit tab button to insert spaces to the next tabstop or shift-tab to delete to the previous.

Collapse
 
andreanidouglas profile image
Douglas R Andreani

first time I saw people using spaces other than tabs I couldn't believe. it takes one click for tabs while three/four for spaces. I think it's only matter of personal preference and you will not change other person states of mind.

Collapse
 
val_baca profile image
Valentin Baca

This is a common misconception.

No one presses their spacebar 4 times. The tab button inserts spaces to the next tab stop and shift-tab removes them to the previous tab stop.

Collapse
 
andreanidouglas profile image
Douglas R Andreani

Well, maybe most of the people use like this, but I saw people hitting space.

Collapse
 
s_anastasov profile image
Stojan Anastasov

I don't care as long as it's consistent. The consistency should be enforced in an automated way, eg a tool run on a CI server.

Collapse
 
6igo profile image
Bensigo Egwey

Tabs save you file size

Collapse
 
sam_ferree profile image
Sam Ferree

Most importantly, consistency matters more than anything else... Consistent with your team, the languages requirements, style guides, all of these things need consideration. That being said, tabs. The answer is clearly tabs.

tabs is the indent character, and it creates smaller file sizes.

But it could look different on other peoples machines!

Exactly, you should respect other people's preferences of logical indentation. I could use my preferred indent of 2, and other people, godless swine that they are can have 8 if they want...

But how do I?

public int add(int a,
               int b,
               int c)
{
  //And get this to line up?
}

Well you just...

public int add(
  int a,
  int b,
  int c)
{

}
Collapse
 
ihesiulor profile image
. --. ..- ... ..

would make for a good discuss in future tho....

Collapse
 
niorad profile image
Antonio Radovcic

Don't care, my editor should auto-format on save to whatever is the project- or language-standard is (Prettier JS, gofmt etc.)
Without those, I'd stick to tabs, because it exists for the exact purpose of aligning lines, as opposed to spaces, which don't.

Collapse
 
rhymes profile image
rhymes • Edited

Use shared conventions.

For example in Python basically everybody uses spaces (some two, some four), the style guide favours spaces. Same for Ruby. Go uses tabs and that's it.

I tend to adhere to commonly shared style guides. Also, let the lint tools format your code, they are better than humans :-)

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y
Collapse
 
sudhansubedi profile image
Madhu Sudhan Subedi • Edited

#tabs

One Reason: It saves your time

Collapse
 
outthislife profile image
Talasan Nicholson

.editorconfig

Collapse
 
val_baca profile image
Valentin Baca

This is a common misconception.

No one presses their spacebar 4 times. The tab button inserts spaces to the next tab stop and shift-tab removes them to the previous tab stop.

Collapse
 
raventhedev profile image
Chris Raven

Tabs configured to be either 1x Tab or 4x Spaces, depending on the official style guide of the language being used ;)