Hacker News new | ask | show | jobs
by chrisweekly 335 days ago
The choice isn't (tabs) vs (spaces).

It's (tabs && spaces) vs (spaces).

In the real world, there will always be spaces, whether used for indentation or not. Using tabs for indentation inevitably leads to a mix of both - which is, objectively, worse for maintenance and consistency.

4 comments

And if people didn't align text, you could still make an argument that people use spaces to separate identifiers or otherwise tokens, therefore it's spaces vs tabs&spaces…

Tabs are for indentation, to align the beginning of the line, later on if you want to align text somehow, use spaces. You probably shouldn't align lines with different indentation (I align rarely so I can't remember ever to do that).

the correct rule is: tabs to indent, spaces to align

[TAB][TAB][TAB]ShortTypename[SPACE][SPACE]variable_name

[TAB][TAB][TAB]LongLongLongTypename[SPACE]variable_name2

ps. the [SPACE] counts above are illustrative, not accurate.

The correct rule is: you shouldn't align.
The code I maintain (Emacs Lisp) follows that rule.
Exactly, just have your linter error out if there's a tab following a space
And ever stronger if a space follows a tab..!
That's how you do alignment (in indented parts)
Just imagine pressing the space bar 12 times for each line, or having to use :vimq! to handle that without going crazy
Not to mention that space is a normal printable character, while tab is a control character, like carriage return. Control characters have very well defined meaning, that is very different in different contexts.

As an example, and I hope this is not a new information for most, in many text terminals it does not mean "advance forward to a multiple-of-8 position", it means "advance forward to next tab stop", and you can arbitrarily set those (e.g. HTS/TSC on vt220)

If tabs or spaces are mandated at editor level, how are you editing Makefile or TSV files?

I really do not understand anyone, who is against having support for any possible indentation, controlled by the user as is necessary for each use case.

I'm amazed that your comment is the single reasonable take among this entire discussion full of unsupported assertions and opinions.

Having two different invisible characters to represent empty space is objectively worse. Just use space, and the tab key to insert multiple spaces. Simple. Use .editorconfig and a formatter to enforce the commonly accepted standard. Done.

Sadly you still have to make exceptions for Makefile, Go, etc. that expect a mixture of hard tabs and spaces. Otherwise hard tabs are not allowed in the codebases I manage, and are replaced by the formatter.