
Ask HN: Tabs or Spaces? - baron816
Tabs or Spaces?
======
citrusx
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.

~~~
edoceo
Why force your preferred indentation display on others? #arrogance

~~~
jjpe
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.

------
takatin
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

~~~
lumberjack
>There's a reason we put tab key on every keyboard out there

To insert 4 consecutive spaces at once.

------
datalist
Tabs.

I used to prefer spaces until I came across an argument which convinced me to
convert:

 _Indentation can be something very subjective, some prefer two spaces, others
four and yet again others maybe eight. With spaces everyone is forced to use
one particular style. With tabs everybody can configure it exactly the way
they want and it will be displayed in one unified style._

~~~
stasm
The problem with this customization is that different styles end up with
different allowed character counts in a single line. For linters to work as
expected you still have to hardcode the number of spaces a tab should count as
in the linter's config. At which point you could just use spaces and treat
indentation as part of the content—not presentation.

------
louis-paul
Tabs. Spaces for indentation are an heresy.

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

------
marksamman
Tabs for indentation, spaces for alignment.

~~~
nilved
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.

------
doc_holliday
Spaces of course.

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

~~~
doc_holliday
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.

------
NKCSS
Visual Studio automatically converts tabs to spaces (default setting; can be
changed). Personal preference; 2 indent (spaces) instead of full 4.

~~~
jdhzzz
Seconded. Ultra edit does the same tab->space conversion.

------
rmurri
Mixing tabs and spaces is the worst. I'm surprised none of the commenters has
mentioned line continuations, which tabs suck at. Since I can't mix and match
I prefer spaces.

------
poops
I prefer tabs because it doesn't force all devs to have the same level of
indentation.

------
satysin
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.

------
joewood1972
The best answer is to use a tool that saves in the format that the file was in
originally. I think VSCode and some others do that. If the file only has
2-space indentation then TAB becomes 2-spaces. etc...

That said, assuming a greenfield the best case has to be to use tabs. This way
if somebody has a preference to small indents then they can configure the TAB
to render as 2-spaces - it becomes a render issue.

So, use a modern tool and it's a moot point.

P.S. not sure why Silicon Valley's Richard started talking about 8 space tabs.
That would be crazy. The only time I've seen that is in a proportional font in
a word processor.

~~~
gumballhead
GitHub renders tabs as 8 spaces. It is crazy and looks ridiculous.

~~~
jon-v
This is actually the only truly rational defense I can come up with for my
preference of spaces vs tabs. (The generic argument is that the code will look
the way I want it to even when rendered by a tool where I can't control the
tab width, but Github is the only real example these days.)

------
zerr
Here is the compromise: one tab in between two spaces.

~~~
maze-le
Are you into esoteric programming?

[0]:[https://en.wikipedia.org/wiki/Whitespace_(programming_langua...](https://en.wikipedia.org/wiki/Whitespace_\(programming_language\))

~~~
zerr
No, I'm radically against significant whitespaces.

------
zastrowm
Spaces. A single character shouldn't expand to look like multiple characters.

------
codewritinfool
Tabs. I like controlling the level of indentation I see.

------
yellowsir
tabs, don't you watch sillicon valley?

~~~
zappo2938
I was in tears when she said she uses Vim.

~~~
yellowsir
the show is only getting better ;)

------
bryanlarsen
I wish the answer was elastic-tabstops [http://nickgravgaard.com/elastic-
tabstops/](http://nickgravgaard.com/elastic-tabstops/)

But compatibility trumps awesomeness, so spaces.

------
maze-le
Since my first contact with Python: spaces!

------
gregjor
Tabs, but this shouldn't be an issue for programmers using a real editor,
something more sophisticated then Notepad. Vim can convert between tabs and
spaces easily, and almost every modern editor I've used can do the same.

Using spaces to force everyone to your preferred indentation is like forcing
the font size. I can't read code indented two spaces, but if we use tabs I can
set the indent to 4 spaces widths and someone with younger eyes can use 2.

------
jibsen
Most importantly, whatever the language or codebase you are working in/on
mandates.

I write a lot of C, and given the choice, I tend to prefer tabs for
indentation and spaces for alignment. I use a tab-width of 8, so the code will
look fine for anyone using a lower tab-width.

Converting from tabs to spaces is a simple search-and-replace, whereas the
other way is more work (there was an article here recently about algorithms to
guess indentation width).

------
RaycatRakittra
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.

~~~
datalist
Can you elaborate on what problems you encountered with tabs in a Unicode
context?

------
aibotter
Spaces over Tabs, Vim over Emacs! #TeamNoSexForRichard

------
egwynn
Ideally tabs. That's what they're for. But at some point someone on your team
who doesn't understand the difference is gonna start making changes and screw
it all up. Because of this, I use spaces. That way it always looks the way I
intend it to look no matter how poorly the viewer's text editor is configured.

~~~
datalist
Mixing styles will always lead to a mess though, regardless of whether one
uses tabs and then someone "introduces" spaces or vice versa. Using spaces
wont help much in that case.

------
koolba
Whatever the file already has.

If it's empty, spaces.

------
Nejohnson88
Tabs all the way man it so much easier for code control.

------
rajington
i write pre-minified js, all in one line.

~~~
ddri
thisonemademelaughoutloud

------
pvinis
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!_

------
verytrivial
Yes. Just not both.

------
olouv
Spaces! [https://github.com/airbnb/javascript#whitespace--
spaces](https://github.com/airbnb/javascript#whitespace--spaces)

------
drinchev
It doesn't matter. Just choose tabs or spaces per project and be consistent.

If you join a project already using tabs / spaces and you wanna switch, don't
bother doing that.

------
king_magic
Spaces.

------
lucasnemeth
spaces, tabs are nonsense

------
insin
Spaces for indentation, spaces for alignment...

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

~~~
ancarda
I think she did that just to see if he would get annoyed.

------
wrong_variable
spaces ( I know I am a monster, stop staring at me ! )

------
ebbv
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.

------
joesmo
I don't care and I only want to work with engineers who also don't care and
would rather spend their brainpower on actual problems, not bikeshedding.

------
wcummings
(setq indent-tabs-mode nil)

------
kavehmz
Neither,

Go or Python, so I don't spend time on this trivial decision anymore.

