6 ms·
After 20+ years of listening to the tabs-vs-spaces debate and considering all the legitimate points that both sides have, many have made the following observati
by jasode 10y ago
After 20+ years of listening to the tabs-vs-spaces debate and considering all the legitimate points that both sides have, many have made the following observation and it's what resonates with me the most:
In an ideal perfect world, _all_ of programmers and _all_ text editor tools would use tabs specifically for indentation and spaces specifically for alignment. But, we don't live in that perfectly coordinated world so spaces maintains the most fidelity -- at the expense of programmers not being able to instantly customize the indentation from widths of 2,4,6,8.
Therefore, the slight edge goes to spaces even though I find tabs extremely attractive. (That conclusion is in the context of a team of multiple programmers, using multiple languages, multiple text editors. If you're solo and can maintain "tabs discipline", that's a different scenario.)
- CJefferson 10y agoMy other personal feeling is that it's easy to auto-check we aren't using tabs (just search for tabs, and reject if any are found). Depending on how you choose to format, it can be arbitrarily hard to check tabs are being used correctly. For example, many people want to do some space indenting, such as: <tab>void my_function(int arg1, int arg2, <tab> int arg3) <tab><tab>{ It's (I believe) impossible for a language-agnostic tool to know this is "correctly tabbed", but (for example) <tab>void my_function(int arg1, int arg2, <tab> int arg3) <tab> { Is not.
- akerro 10y agoI just always enable "Show whitespaces" in any editor I use. https://i.stack.imgur.com/BP2WJ.png https://i.stack.imgur.com/BP2WJ.png This let's me know if I left any trailing tabs/spaces before committing, align code better and while writing not while "refactoring". git commit -am 'Whitespace formatting changes only' No.
- scrollaway 10y agoDon't align. void my_function( int arg1, int arg2, int arg3, ... ) {
- hamax 10y agoI also much prefer this way of breaking long lines. Aligning parameters always looked ugly to me, specially with long function names.
- CJefferson 10y agoWhile I quite like that style, now you have to convince people to never align, before you can convince them to use tabs. I've not seen any large public code-bases uses this style, so it's hard to know how well it works in practice. Do you know of any major projects with a 'no alignment' requirement?
- MatmaRex 10y agoMediaWiki uses tabs for indentation and discourages alignment. https://www.mediawiki.org/wiki/Manual:Coding_conventions https://www.mediawiki.org/wiki/Manual:Coding_conventions
- realharo 10y agoI also like a rule that states that you either put all the parameters on one line, or each one on its own separate line, but never something in between.
- exDM69 10y agoI don't think blindly following any convention is good. Sometimes it makes sense to group a few parameters, take this toy example for instance: void drawrect( Surface *surf, int x, int y, int width, int height, uint32_t color); Grouping relevant arguments just makes it a bit more legible. It's even more useful when calling the said function (assuming function with a lot of parameters, say XCreateWindow).
- gepoch 10y agoUnless you're using golang,in which case gofmt will correct you. Hence the overwhelming consensus of the go row for tabs.
- kgwxd 10y agoGo's adoption rate would be quadrupled if they had chosen spaces instead of tabs. It's a fact.
- lbn 10y agoFact? My team is using Atom, VS code, IntelliJ and vim-go for Go. There has never been a problem with tabs vs spaces. On save gofmt converts all spaces to tabs and when I open Go files in vim-go it converts them to spaces according to my settings. Same for all other editors, whether you like tabs or 7-space indent.
- miloshadzic 10y agoPretty sure it was a joke...
- akerro 10y agoor python, or rust.
- pluma 10y agoPython doesn't care either way as long as indentation is consistent (though there's a common misunderstanding that Python cares). However PEP-8 specifies that code should be indented using 4 spaces and editors should be configured to render tabs as 8 spaces (likely to make mixed tabs & spaces really obvious). But PEP-8 also specifies that code should follow whatever is the coding standard in a given project. IOW, Python is actually far more pragmatic than most people (including most Python programmers) think. It just has a culture that strongly advocates following the rules (i.e. PEP-8 and PEP-20).
- Fuxy 10y agoHonestly I don't care either way just a long as the file doesn't mix tabs with spaces. I hate when the code looks perfectly aligned in my editor but is completely messed up in git because git renders tabs a different with. I personally prefer spaces on my own projects because in the early days a tab used to be fixed at 8 spaces and I though that was a bit too much. It's adjustable now but I don't think it was then or at least I wasn't aware it was.
- louthy 10y agoI came to this conclusion too after at least 20 years of using tabs; but mostly it was because of moving to white-space significant languages like Haskell, F#, etc. It was just too painful getting everything lined up with tabs and I needed the fidelity of spaces. Previous to that with C/C++/C# the alignment usually took care of itself through the closing brace and IDE auto-formatting. So tabs was the natural unit of currency there. Horses for courses I guess.
- spinningarrow 10y agoPersonally, I don't find the value in alignment - indentation is all I do. I especially dislike alignment of this sort: var a_variable = 1; var another_variable = 2; var yet_another_variable = 3; which is just too fiddlesome and in fact makes it _harder_ for me to read.
- zbjornson 10y agoThat's also hazardous when you later add an_even_longer_variable and then have to modify three extra lines to make them align.
- spinningarrow 10y agoExactly. To be fair, I believe most popular editors have plugins/shortcuts to do this. Or at least I hope people aren't doing this manually.
- dkuntz2 10y agoBut if anyone looks at a diff, it looks like all the lines have changed, instead of just one, taking just a tiny bit more cognitive overhead.
- citrusx 10y ago`git diff -w`
- tnorthcutt 10y agoBut `git blame` still sees the whitespace change, right? Edit: turns out `git blame -w` works as expected, ignoring whitespace. The More You Know™
- jasonpeacock 10y agoThat's what code formatting tools (cncrustify, clang-format, etc) were built to fix - let the computer have perfect and consistent formatting, you just need to record your intention.