[Poll] Tabs or Spaces?

1    15 Aug 2016 11:13 by u/cyzoonic

Let's settle this once and for all. Do you use tabs or spaces to indent your code? Which is better?

26 comments

12

A space is a space, no matter the editor. Most editors have a "translate tabs to space" feature so you can use tabs like you normally would.

I use spaces, one tab is four spaces.

Edited to add: use whichever you want but for the love of all that is good and holy, be consistent. I convinced my team at work that it was important to all choose one or the other and to format any file correctly if they touched a single line in it. At first it meant a lot of big merge requests, but over a two month period every one started to say the code was more readable because of it. I was desperate for consistency I even offered to do tabs even though I am a vocal spaces supporter.

10

Tab. It's only one button press, it's easier to move through with the arrow keys because you don't have 10+ spaces to press through, and if people have different preferences, they can adjust how it displays for them without actually changing the content.

Only exception would be alignment, but it's not that big of a deal.

8

Tabs: because editors can do all that auto-adjusting for you. Also, because I learned how to type on an old fashioned manual type writer.

I hate people who mix tabs and spaces. I have my editor set up to show invisible characters and its amazing how many people in open source projects mix tabs and spaces.

I suspect those who mix are space supporters.

2

I'm a spaces guy myself. Whatever you choose, be consistent; and if working on a team, hash it out before you're thousands of lines deep.

2

Spaces. I've set VIM up to automatically replace a TAB-press with four spaces, so I don't bork up my Python scripting... god, I hate Python...

4

god, I hate Python...

it's pretty rare to see that written.

3

Yeah, I hate how volatile it is... changing syntax, every version, for no good reason. Makes old code broken, just because. Print syntax, read syntax, and any other basic syntax change, from one version to the next, making writing anything a chore. For instance, you have:

print 'Hello world.'

print "Hello world."

print("Hello wold.")

and only one of those is right, or all of them are right... depending on which Python version you're using. Why would you do this to me, Python?

This volatility means that certain projects, written with certain code, can only be run correctly with certain versions of Python. So, not only do you have to standardize your code, depending on what you want to do, and how you want to do it, but your sketches HAVE to be run is a standardized version of Python. That's why YouTube is written with Python2.7-something and Python is now on v3.5.2! Google hasn't made the version changes, because of this volatility.

Then there's the space/tab mismatch, which we're talking about here. I do pretty well, staying away from it as an individual, but it always comes around and bites me in the ass in group projects. Nothing chews me more than having invisible characters, somewhere in your code, stop your code from working... even though both sets of invisible characters are acceptable!

I hate the language. It's convenient, with all of its libraries and hardware-level access, but it's generally a pain in the ass. If Python disappeared tomorrow, I'd be a happy man.

1

the movement from 2 -> 3 is huge, and it is treated as 2 separate languages for the most part. usually code does not break between subversions and only features are added, for example most 2.6 code should have worked fine in 2.7. even more fun is the formatting:

foo = 'thing1'
bar = 'thing2'
print('%s %s" % (foo, bar))
print("{} {}".format(foo, bar)
print("{foo} {bar}")

i thought there was a 4th way, but i can't remember it right now.

0

You must use Python a lot... but, you know, as volatile as Python is, I'm sure they'll add another way of doing this, remove all of these options, and make one of the ones you stated do something COMPLETELY different... like they did with raw_input and input.

It's convenient, and I use it often, but I can't say that I enjoy using it. I'm always on my guard, about what I'd typing, because (like I said) it's always different among versions. I know each language has to grow and expand, but some of the leaps for Python go WAY beyond just that... which is why I call it volatile. Some of the changes they have made make no sense, are frustrating, and only serve to break code for previous versions... for the life of me, I can't figure out the input-tango they did, or why they did it.

I usually default to Python, when I'm working with hardware-level stuff, or a small sketch that I need to hammer out in a minute, or two, but I still hate it all the same...

2

if you primarily write in a language that requires correct spacing (python, julia, restructuredtext, markdown, etc.) then you will prefer spaces, if you don't then you probably just go with whatever you use, not for any strong reason, but just because that's how you (or your ide) do it.

I find that when working with tab people on projects that don't require spacing (like latex, c++, etc.) there are many inconsistencies because of this; i hate it.

1

tab

1

Tab, sometimes my editor replaces my tabs with spaces for me. But I want tabs dammit! I see no reason to be pressing space 4 times just to indent, slows you down too much.

1

What the hell kind of shittyass editor are you using that can't be told to automatically insert however many spaces you want when you hit Tab? You code in Notepad brah?

1

There's probably a way, I just can't be bothered to look for it tbh, nowadays I'm using the fork of Nano I wrote (it adds line numbering), but sometimes I use Atom.

1

Learn Vim. I used to use Nano and then learned Vim and I'm so glad I did.

1

Nah man, I hate modal editors, they just slow me down and I won't be able to remember all those keybinds. Whatever, I'll just code it into nano at some point if I can be bothered.

1

Nano is modal too, every time you press Control and such. Remembering the keys to do things comes with practice and actually using them.

1

Depends on what is written in the language style guide. I have no problem setting my vim configs for each file type if needed.

1

Tabs, and I don't mix spaces with my tabs.

1

Tabs if I am using an editor for the more popular languages, otherwise I use spaces for some of the more obscure ones.

Unfortunately I can't tab in this textbox to see how many spaces it is.

1

both according to scenario

0

A tab could be a different number of columns depending on your environment, but a space is always one column.

In terms of how many spaces (or tabs) constitutes indentation, it's more important to be consistent throughout your code than to use any specific tab stop value.