6

Spaces vs tabs has kind of become a non-argument for web tech and the former has won (at least in every place I've worked or observed in open source projects).

Although I don't really care (just stick to one for the same codebase) I don't get why spaces won. Given the argument is mostly about how we like to read code individually, and tab width can be configured per editor while space cannot, why did spaces win?

Comments
  • 0
    Interesting. It's always been tabs as the winner at the places I've worked regardless of the language or platform.
  • 6
    Spaces always win for me because of alignment. You cannot vertically align similar lines if you use tabs for indenting, because tabs are of indeterminate width. (I also hate needing to the change tab width in vim and terminals so it isn't freaking 8 wide.)

    You can use tabs for indentation plus spaces for alignment, giving you the best of both worlds, but mixed whitespace is blasphemy. Git cli also complains about this.

    So: spaces.
  • 2
    @monkeyboy There's a high chance that your IDE/editor just puts spaces by default and you haven't noticed.
  • 1
    Root is probably right on this one, spaces let you align stuff more creatively. But https://reddit.com/r/javascript/...
  • 3
    Spaces always works as intended, whereas tabs will require support from editors and IDEs. Moreover, if you, as I, work on different platforms using different editors (vi/vim, emacs, Eclipse) your work will be so much harder if there are tabs in our code instead of spaces. The only drawback with spaces is that the file size get a little higher, but I can live with that.
  • 0
    @stormwise Which editors don't support spaces? What kind of multi-platform problems do they cause?
  • 0
    @gronostaj All editors I know support spaces. They also support tabs but they are handled differently, which is the root of the problem. If you have written a file in emacs using tab setting of, say, 2 and then open the file using vi where default is 8, your work will be be more difficult. What is really annoying is spaces and tabs in the same file!
  • 1
    @stormwise Sorry, I meant tabs. That's kinda the point though, tabs win accessibility-wise. If you're using them only for indentation, not some fancy alignment, they work fine.
  • 0
    @Jilano nah, VS settings are enforced with a .editorconfig file.
Add Comment