Ask HN: Tabs or Spaces?

20 points by baron816 ↗ HN
Tabs or Spaces?

67 comments

[ 5.0 ms ] story [ 135 ms ] thread
tabs, don't you watch sillicon valley?
I was in tears when she said she uses Vim.
the show is only getting better ;)
(comment deleted)
spaces ( I know I am a monster, stop staring at me ! )
Tabs for indentation, spaces for alignment.
I agree with this to the extent that I will say it's the sensical answer. I think that tabs are an obvious choice because they are semantic intendation rather than generic spacing. For this reason the front-end can render them with 2, 4, 8 or whatever amount of spaces, without requiring the code be changed.
Visual Studio automatically converts tabs to spaces (default setting; can be changed). Personal preference; 2 indent (spaces) instead of full 4.
Seconded. Ultra edit does the same tab->space conversion.
Whatever the file already has.

If it's empty, spaces.

Spaces of course.

Tabs can be messy across version control and multiple users with differing OS / editor.

And to add... there is no excuse not to use spaces even if you like the tab key.

Configuring your favourite text editor to interpret a tab key press as 2, 4 or whatever number of spaces for your project is trivial.

(comment deleted)
Many people use tabs in the beginning of the line, and spaces for anything after any visible character in the line.

If people choose a different way, is because they have a reason, or they don't care.

If you're not sure, use whatever the file already uses, or the way I described above, or whatever makes you feel fuzzy inside. In that order!

Tabs. There's a reason we put tab key on every keyboard out there, it is built specifically for alignment

  The word tab derives from the word tabulate, which means "to arrange data in a tabular, or table, form." When a person wanted to type a table (of numbers or text) on a typewriter, there was a lot of time-consuming and repetitive use of the space bar and backspace key. — https://en.m.wikipedia.org/wiki/Tab_key
Tab is great for auto-complete.
>There's a reason we put tab key on every keyboard out there

To insert 4 consecutive spaces at once.

What the purpose of the backspace key?
Spaces for indentation, spaces for alignment...

...but using the tab key /glares at Silicon Valley/

I think she did that just to see if he would get annoyed.
(comment deleted)
Somebody watched Silicon Valley last night :)

And I go with whatever the current file is. If I didn't make the file I respect the style of whoever did.

For my own files I prefer spaces.

For a very long time, I thought tabs were the way to go. It provided the most compatible coding style between my languages (Lua, C, Assembly, etc.) The only sticking point was JavaScript, which used spaces. But now that I develop across devices, I'd have to say spaces simply because of encoding issues re: Unicode. Sure, you could ensure your encoding type, but that's an extra step you shouldn't have to do.
Can you elaborate on what problems you encountered with tabs in a Unicode context?
Tabs. Spaces are how you end up with one class where one method is 2 space indent and another is 4 and another is 12 because your team all has different preferences (and two of them are insane.)

Tabs means everyone can use whatever preference they want and not be bothered by anyone else's preference.

Since my first contact with Python: spaces!
Tabs. Spaces for indentation are an heresy.

To go further, always use a standard formatting tool (gofmt, clang-format...) before committing code.

Spaces.

The variability in the ways tabs are displayed, which you can not control, make tabs a non-starter.

Spaces always look like spaces. So when you use them, your text looks the same wherever it is displayed, and that requires no additional work.

The one caveat here (if you don't already know) is that the `make` utility has never been updated to allow spaces, even to this day. So, you must use hard tabs in Makefiles.

Also worth knowing is that Python's official style guide, PEP-8, insists on spaces (specifically, 4 spaces), and the officially-provided formatting tool for Go uses tabs (a decision that I was most displeased with). It's physically possible to go against these recommendations, but you're not likely to find any community cooperation for that decision if you're working in those two languages.

> The variability in the ways tabs are displayed, which you can not control, make tabs a non-starter.

You can absolutely control the way tabs are displayed. Using a poorly built tool that doesn't give you that option is the non-starter.

The rest of what you said are just random facts that don't really support your preference.

(comment deleted)
I second what WayneBro wrote.
A downvote for agreeing with someone, seriously?
I didn't downvote you, but your comment doesn't add anything to the public conversation, it just clutters it. Just click the upvote button next time.
Why force your preferred indentation display on others? #arrogance
If it's your code you can write it however you like, usually. That's not arrogance, it's just how this piece of the world works.