you are viewing a single comment's thread
view the rest of the comments
[–] 68 points 6 months ago (33 children)

Are tabs worth two spaces or four?

  • source
  • hideshow 33 child comments
  • [–] 75 points 6 months ago (8 children)

    That's the beauty of tabs, it can be whatever you want.

    But the correct answer is 4

  • source
  • parent
  • hideshow 8 child comments
  • [–] 21 points 6 months ago (5 children)

    I'm a spaces guy, but agree on the 4. A coder told me decades ago that 4 is better than 2 because if your code starts wrapping due to too many indents you should be refactoring it into functions anyway.

  • source
  • parent
  • hideshow 5 child comments
  • [–] 13 points 6 months ago (4 children)
  • [–] 14 points 6 months ago (3 children)

    In part, because it forces 2-space tab users to confront the indentation issue above

    Also there are no drawbacks.. I still hit the tab key to indent (and shift tab to dedent). My editor does the rest.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 14 points 6 months ago (1 child)

    The drawback to spaces is that people with vision issues or dyslexia lose the ability to make the code more readable in their IDE by adjusting tab size.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 5 points 6 months ago

    I can't speak to dyslexia (but in would guess that 4 spaces is easier than 2?).

    At my last job we had a default linter policy of 4 spaces across all languages (python, JS, rust, mostly). We also had a blind coder. He never mentioned it. I'd guess screen readers are capable of dealing with it these days?

  • source
  • parent
  • [–] 15 points 6 months ago* (7 children)

    I've heard of 8, 4, and even 3 which is pretty crazy... how could it possibly be 2!?

  • source
  • parent
  • hideshow 7 child comments
  • [–] 10 points 6 months ago (3 children)

    2 spaces is pretty common in JavaScript... And I think I remember it being pretty standard in HTML way back when. Screens used to be smaller, with low resolution. 4 spaces was a luxury.

    Isn't 2 spaces the standard in Ruby? I don't use it, but I've heard such things.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 7 points 6 months ago (2 children)
  • [–] 14 points 6 months ago* (5 children)

    I might have the solution: Elastic Tabs. They di what tabs were always meant to do from the start, whilst also fixing the shortcomings that spaces are currently used to fill.

  • source
  • parent
  • hideshow 5 child comments
  • [–] 2 points 6 months ago (3 children)

    Wtf is this witchcraft and how can I use it in VS Code?

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 6 months ago (2 children)
  • [–] 3 points 6 months ago (2 children)

    However many I feel like that day. Sometimes depends on the language and use case - if it tends to be deeply indented, I'd gravitate towards 2.

    If using actual tabs, you can change how they appear just for yourself without touching the actual code; the same can't be said about spaces.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 6 months ago (1 child)

    I was trying to stay out of the fray but this one I feel I have to respond to:

    tabs, you can change how they appear just for yourself without touching the actual code; the same can't be said about spaces.

    This is why I use spaces. A space is a space everywhere, a tab depends too strongly on the editor. I've had too many times where I had to edit on a different machine and it transmogrified my tabs into a different non-character entity in a way that didn't reveal itself until later.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 6 months ago

    I can kind of see your point if you're speaking from a devops/sysadmin's point of view (i.e. something that would require you to use default editors on the go on systems that you don't necessarily have control over).

    Other than that, a tab's principal purpose is indentation. One tab is one level of indentation regardless of how it appears. If a tab gets transformed into something else, it sounds like a text encoding problem and indentation would then be just one of (and possibly the smallest of) several possible issues.

    I'm speaking from a web dev's point of view - I'm assuming that I'll always have my own configured editor on hand and I'll be able to tell it that one tab is N spaces, sometimes even differently for different file types in the same project. Worst that could happen is that I don't have a specific configuration and the editor just falls back to the default until I set otherwise. Since I'm working in a team, using spaces for a source controlled project would mean that everyone has to use the same. Having tabs means that everyone can configure it for themselves (assuming editor configs don't go in the repo).

  • source
  • parent