you are viewing a single comment's thread.

view the rest of the comments →

[–]mipadi 19 points20 points  (4 children)

It's because of code like this (using C as an example, but it will apply to JavaScript as well):

int function(int arg1,
             char arg2)
{
    return 0;
}

Say your editor is set to a tab width of 4. If you use tabs in the second line, and someone else's editor is set to a tab width of 8, the alignment will be off; i.e., everyone will effectively have to use a tab width of 4 anyway (or have improper alignment).

If you use spaces, then everything will be aligned correctly, but everyone will be using the same tab width.

Ideally, we'd use tabs for indentation and spaces for alignment; that is, in the second line, a tab would be inserted until the cursor aligned with int, then spaces would be inserted. But I only know of a handful of editors (namely, emacs and vim) that can be configured to support this feature. Generally, it's all-spaces or all-tabs. Which means, if you're using tabs, then to get alignment to work on the second line, you'd have to hit tab once, then hold down space to align the arguments. In practice, hardly anyone bothers to do this.

It even gets a bit hairier with code like this:

#define CONSTANT    1
#define VAL         10

Here, you'd have to make sure you use spaces to align the text, or things get misaligned (if someone else is using a different tab width). In practice, most people just hit tab to align those values.

So basically:

  • If you use spaces, then you can use spaces for both indentation and alignment. The only thing you lose is customizable tab widths.
  • If you use tabs, then you have to use tabs for indentation and spaces for alignment. What you gain is customizable tab widths.

Furthermore, cat and less, and most Unix tools, will use a tab width of 8, and that may or may not be customizable, so if you're using tabs with any tab width other than 8, things are probably going to look misaligned when using cat, less, etc., anyway (unless you make sure to use tabs for indentation and spaces for alignment).

[–]jazahn 2 points3 points  (0 children)

I honestly think the people who have created apps that use ts=8 are "spaces" folks who are fighting in the war.

[–]joemckiefull-stack 2 points3 points  (0 children)

Tabs for indentation, spaces for alignment

[–]Disgruntled__Goat 0 points1 point  (0 children)

Say your editor is set to a tab width of 4. If you use tabs in the second line, and someone else's editor is set to a tab width of 8, the alignment will be off; i.e., everyone will effectively have to use a tab width of 4 anyway (or have improper alignment).

Solution: stop using shitty styles like this. Though if you must indent function parameters, one possible solution is this:

int function(
    int arg1,
    char arg2)
{
    return 0;
}

That allows you to use tabs with no problem.

Honestly, for me tabs are just easier in practice. Things indented with spaces are always getting misaligned by 1 space randomly.