3 ms·
I prefer spaces purely out of consistency reasons. Some systems say a tab is 8 spaces, others say it's 4. Some editors can set a tab to any customizable N spac
by dvt 7y ago
I prefer spaces purely out of consistency reasons.
Some systems say a tab is 8 spaces, others say it's 4. Some editors can set a tab to any customizable N spaces. But a space is always a space so your code will look like you intended (or should I say indented) it no matter who's looking at it.
- tedmiston 7y agoWhile I agree with you personally, I could see the counterargument of: A tab is always a tab, and I can tweak my IDE to render a tab as however many spaces I like (2, 4, 8, etc) without changing the code.
- qes 7y ago> I can tweak my IDE to render a tab as however many spaces I like Sure, IDE's are easy (though many people use multiple IDE's and/or editors across multiple machines). I've also got a couple diff tools, a few VCS's, also the online parts of VCS like web-based pull request review UI's. Tabs also tend not to play as nice with vertically aligned elements, if you prefer that for things like say the '.' on multi-line chained method calls, or longer function parameter lists.
- funkymike 7y agoI'm a tabs for indentation, spaces for alignment person myself. A multi-line statement should have the same number of tabs on each line. Any line after the first should then have spaces as needed. I'll work without complaint or changing it with any existing code whether spaces or tabs. Mix the two for indentation however and fixing it is the first commit I make before touching anything else.
- dvt 7y agoIn a lot of cases though, you can't change what a tab is (consider looking at code on GitHub).
- tedmiston 7y agoThis is a good point. Maybe at some distant point in the future we will softly decouple formatting from code by delegating it all to finely tuned autoformatters, or totally decouple it by storing code in a slightly more abstract form such that whitespace rendering becomes largely a presentation preference.
- ChrisSD 7y agoYou can on Github but it requires using `?ts=4` in the url or committing an editorconfig file. Perhaps there are extensions that do it automatically.
- dschnurr 7y agoReasons to prefer tabs: https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/ https://www.reddit.com/r/javascript/comments/c8drjo/nobody_t...
- anchpop 7y agoI don't understand this reasoning, I can set my editor to show x-spaces at the beginning of a line as however many I want. So I can make code indented with 2 spaces look like it was indented with 4.
- nemetroid 7y agoThat approach doesn't work if you use spaces both for indentation and alignment, you'd only want to multiply the indentation spaces. What editor has that setting?
- shawnz 7y agoWhy would you "intend" for your indentation levels to be a certain pixel width on the reader's screen? Shouldn't that be the reader's choice?