5 ms·
Yep! If people used tabs, then everyone can display it how they like and these stupid discussions wouldn’t be necessary. Alas, for some reason the world has ral
by dkersten 7y ago
Yep! If people used tabs, then everyone can display it how they like and these stupid discussions wouldn’t be necessary. Alas, for some reason the world has rallied behind spaces. Sigh.
- jjgreen 7y agoboth?
- dkersten 7y agoWhat do you mean?
- markrages 7y agoTabs for indentation, spaces for alignment. It is called "smart tabs" and good text editors already implement it.
- edflsafoiewq 7y agoIf you use spaces, you can check that files are okay by forbidding \t. If you use tabs, you can check that files are okay by forbidding /^\t* /. If you use tabs for indentation, spaces for alignment, ??????
- markrages 7y agoMy editor maintains it automatically, so it is never wrong. There is nothing to check. I'm sure there is a command-line pre-commit formatter I could use. But I have never tried to set it up, since I can reformat existing code with a couple of keystrokes in my editor.
- mrgriffin 7y agoForbid "\t* *\t"?
- deleted 7y ago[deleted]
- edflsafoiewq 7y agoOk, but if you get "\t[space][space][space][space]", how do you know this wasn't supposed to be "\t\t"? That is, how do you know trailing spaces are for alignment and not for indentation?
- jlokier 7y agoA code formatter knows, so your editor and other tools can also know. Most editors have code structure parsing of some kind built-in for tabbing already. E.g. pressing the <tab> key indents the current line to match the structure of surrounding code (or cycles between valid indents for something like Haskell or Python). So they know the difference between initial indentation (that people want to be able to configure visually) and alignment.
- jjgreen 7y agois a joke: https://bigc.at/tabs-vs-spaces.orz https://bigc.at/tabs-vs-spaces.orz
- jcranmer 7y agoIt doesn't really solve the problem. How do you format this code with tabs: <TAB><TAB>function name(arg1, arg2, <TABs or spaces?????> arg3 <-- align with arg1) The other issue is with maximum line length. If you have a maximum line length of 80, do tabs count as 2 spaces, 4 spaces, or 8 spaces towards meeting that line length? Using spaces ensures that it at least looks consistent, independent of your tabstop settings.
- ggregoire 7y ago> It doesn't really solve the problem. How do you format this code with tabs: <TAB><TAB>function name(arg1, arg2, <TABs or spaces?????> arg3 <-- align with arg1) Just wondering… do you realign the parameters every time you rename a function?
- samvher 7y agoNot the person you're responding to but I do, or actually spacemacs does. The sequence would be $ -> J -> i -> ENTER -> ESC and I guess it's muscle memory. I agree that this kind of indentation might not make sense on a collaborative project because different people have different standards, but if I'm the only one working on a piece of code I really think precise alignment makes the code a lot more readable.
- mikewhy 7y ago<TAB><TAB>function name( <TAB><TAB><TAB>arg1, <TAB><TAB><TAB>arg2, <TAB><TAB><TAB>arg3, <TAB><TAB>) That means this never comes up, and you don't need to change adjacent lines because you've renamed a function.
- jlokier 7y agoThat wastes a lot of vertical space if you have a lot of function calls. If you're one of those who prefer that, it's ok. I much prefer: function name(arg1, arg2, arg3, arg4, arg5, arg6);
- benibela 7y ago
- samatman 7y agoMy main objection to using tabs has always been that the Tab key is heavily overloaded: it navigates (one Tab press to move the cursor to the correct indentation point), selects (tab completion), and it puts a variable-width character into my monospace-defined text file. I'd rather drop the insertion part and have my editor handle adding an appropriate number of spaces. Let me add this: there's actually nothing stopping you from displaying a four-space indented file as a two-space indented file. Just parse, replace indentation-dictated groups of four spaces with two spaces, you're done. I don't know of a plugin that does this for $your-favorite-editor but it's, y'know, software. There's nothing which prevents it.
- marcus_holmes 7y agoyeah, but then your Version Control system thinks that you changed the file and it needs to commit that change. Which is a ton more hassle than inserting tabs. You could always make CapsLock insert a tab character so you keep the functions of the tab key separate from inserting a tab.