4 ms·
Why would either tabs or spaces be better than the other? Isn't that one of those pedantic style debates that often come down to a matter of personal preference
by zo7 11y ago
Why would either tabs or spaces be better than the other? Isn't that one of those pedantic style debates that often come down to a matter of personal preference? I'd get rather annoyed if someone on my team was constantly changing the indentation from tabs to spaces or vice versa every time they opened a file.
To elaborate on the author's reasoning for using spaces, people sometimes mix spaces with tabs in the indentation unknowingly. If you're not using the author's tab size on your machine, the code doesn't format well at all and if you want to convert to spaces you'd have to manually edit a lot of things. There's also the issue with aligning things as well, which spaces are more consistent for as well. At least with spaces you can see the author's original intention and then reformat it as you wish.
- tinco 11y agoYou're mixing up arguments. No one on your team should be changing indentations. You should decide as a team what your settings are going to be, that's why I suggest using DetectIndent to make sure your settings match whatever the project guidelines are. It's not a matter of personal preference though. Tabs are simply superior for encoding indentation. If you use tabs for indentation you can configure their width in your editor to match your personal preference, spaces doesn't allow for that. That's the only significant difference, and the only good reason for using tabs instead of spaces. None of the arguments you made about spaces make sense. What's the fact that sometimes people mix up tabs and spaces got to do with anything? The whole idea of using tabs is that the code does format well regardless of what tab-width setting you have on your machine. Converting tabs to spaces does not require manual intervention at all. Alignment should be done with spaces, no one is argueing to use tabs for alignment. You can't use tabs for alignment because their width is undefined! The whole idea of using tabs is semantically encoding the authors original intention to allow you to reformat as you wish! At this point.. are you just trolling me?
- zo7 11y agoOh sorry! I completely misunderstood what DetectIndent was doing, that's a good tip. I did want to point out that there's some sense to forcing the code to look the same on every machine though. Of course converting tabs/spaces is automatic, but my point was that the mix of the two requires either manual editing or conforming to the width of whoever made the error. It does happen, and I've been on at least one project with a professor who would occasionally mix things up while in the throes of editing (and they used a tab width of 8 which made it especially irritating for others!). With spaces you at least force whitespace to mean only one thing and if you absolutely can't stand someone's indentation width you can still change it like you can with tabs. This really is personal preference though. Spaces explicitly represent the author's original intention including their indentation width, while tabs make it more convenient to others while conflating whitespace to mean two different things. Both are entirely reasonable though.
- ufo 11y ago> What's the fact that sometimes people mix up tabs and spaces got to do with anything? Its a concession to the fact that humans are imperfect. When I am working with a group of people I find it easier to just use spaces instead of relaying on everyone configuring to use tabs correctly.
- semi-extrinsic 11y agoAs an example of where it's not just personal preference: makefiles require actual tabs, not spaces, in the indentation in recipes for targets. And in Python, mixing tabs and spaces will cause flow control to do something different than what you intend it to. In vim you can handle tabs on a per-filetype basis, eg. I have red syntax highlighting of spaces for indentation in makefiles.