Tabs vs. Spaces

Dan Ihesiulor on March 25, 2018

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

markdown guide
 
 

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.

 
 

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

 

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)
{

}
 

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

 

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 :-)

 

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.

 
  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.

 

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.

 

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.

 

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

 

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

:)

 
 
 

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.

code of conduct - report abuse