Hello everyone !
I was asking myself this morning what are the diffs pros and cons between the use of Space and Tabs in code.
Also what do you use and why ?
Personally I use Tabs because I've never felt the need to change the default config of my IDE/TextEditor and my company doesn't force us to use one or the other (yet!)
Happy Coding!
Update : Thank you all for your answers ! According to your answsers : Consistency is the key :)
Top comments (26)
Tabs are evil
Can't stop laughing everytime I rewatch this, LOL :))
I'd say, it's just a movie, but my geek part in my just can't stop yelling:
Silicon valley has been a great watch
I lol'd :D
I use a soft tab setting 4 spaces. I like a spacious feeling
I like 2 spaces, because I dislike wrapped lines and I hate horizontal scrolling, and a 2-space indent (even a few levels deep) leaves more room for a reasonably-long line, while still being visually distinctive enough to make the indentation useful.
But this is, like, literally the least important thing I can think of. I will do 6 spaces if that's the code style of the project I'm working on. Consistency is more important to me than personal druthers.
Just want to say that automatic readers that blind people use, take more time reading the spaces than the Tabs.
A blind developer friend of mine told me he prefer tabs for that, and just for that is enough for me.
Regards.
I/we use soft tab represented as two spaces and our linter tells us if we're wrong. If I worked in a tab-driven language I'd use tabs.
By the way, this works way better as a discussion like this than a poll, because it's not always clear what people mean by the two answers. The poll and answers are always hilarious though.
two spaces? i want to fight you now.
We need to make formatting simpler:
In fairness, step 1 is the hardest. But the reward of step 3 far outweighs the pain.
Like how Go has gofmt. It's all opinionated in ways I don't like, but I guess you get used to it and at least you don't have to think about it.
Exactly. You're seeing this more and more in modern languages like Go, Python, etc. Formatting is just built-in to the language.
It takes some getting used to. But only because formatting has become such a personal thing.
I use soft tab, setting to 2 spaces, and it's great! working on small screen with big font size (13px), 2 spaces is enough.
But sometime it's conflict with team's coding convention, I solved it with editorconfig files :D
I'm mostly coding Python, I'll let you guess why I'm pro spaces :)
(and
ctrl
+maj
+P
>spaces
>Indentation: convert to Spaces
works great on Sublime Text)It also allows me to align some of my parameters on big declarations without having a messy display.
The repeated space sound bothers me though.
I still prefer tabs over spaces though. š
No needs, you can use tabs and then the shortcut or set tab spacing at the bottom right of the editor
Tabs are the correct choice. I've covered this in my article, Lingering Spaces and the Problems of Overformatting
The key points are:
Projects that use spaces inevitably make it harder for some coders to contribute to their project. And if they fall victim to the second point they make maintenance as a whole harder.
My big concern has always been what the Tabs Are Evil article calls "continuation lines". I think code like this (from that article) is ugly and hard to read.
Instead, why not structure it like this?
Isn't that much easier to read? With indentation levels you know exactly what everything is.
Yes, exactly. If you wish to align things just start them all on the next line.
The space approach is entirely annoying, not because they're spaces, but because all functions have different alignments.
This sucks for readability, but also has a very real cost in maintenance and source control. If you wish to rename a function you have to modify the alignment of all the parameters again, this needless increases the patch size, thus wastes reviewer capacity.
Happily I'm using more Go now, and this fight was decided by the go creators, no more wories for me :))
Also in other languages I use auto-format on save so ... I really don't waste time on pressing tabs or spaces, or semi colons, and {} , that's the job of the IDE.
You will find pros vs cons on the battlefield (internet) but I think most of them are stupid. Because of we can choose our own local font and other IDE settings, you can make tab looks like spaces and viceversa anway.