3 ms·
Why do so many JavaScript devs use 2 spaces for tabs? Its terrible for quickly reading through code
by cyberpunk0 8y ago
Why do so many JavaScript devs use 2 spaces for tabs? Its terrible for quickly reading through code
- arnarbi 8y agoIt's pretty accepted style. E.g. https://google.github.io/styleguide/jsguide.html#formatting-block-indentation https://google.github.io/styleguide/jsguide.html#formatting-...
- abritinthebay 8y agoRuby infected webdev with this awfulness.
- aoeusnth1 8y agoLots of developers work at Google, which enforces the use of two space tabs internally. Personally I’ve come to appreciate it (and even prefer it).
- davidmurdoch 8y agoSomeone (@feross) created something called StandardJS, and even bought the domain standardjs.com, and started advertising it as a great style guide. I initially thought it was a joke or parody, as my own style is pretty much opposite of the guide. Anyway, it says to use two spaces. It got super popular and here we are now.
- workinfunk 8y agoJavaScript has commonly used 2 spaces for years before "StandardJS" (which is now out-of-date because certain es7 features necessitate line-terminating semicolons, but I digress). CoffeeScript was a big catalyst, and I think Rails was as well, but it probably would have happened anyway. Of the languages I use regularly, the only ones for which 2 spaces is not accepted as normal are Python (which uses 4, probably because it was set in stone decades ago, before people even knew how to write code) and Go (whose auto-format uses tab characters, probably because Rob Pike is a stubborn prick). Really, 4 spaces is an awful lot, unless your eyesight is failing.
- ninkendo 8y agoMy theory of tab width is that it should be somewhat proportional to the average height of indented sections of code in that language. That is, if a given language is really verbose and requires a lot of code to do simple things, the functions, if-statements, loops, etc will probably be a lot longer (like in C or Go) and so you need wider tabs to help visually align things. But if a language encourages a style where functions are just a couple of lines long, if statements and loops are rare (or at least comparatively short), having excessively wide indentation can hinder readability.