Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is a very nice write up, but the tabs/spaces part of it makes no sense at all.

"I like it, since it means my source code looks the same on every machine."

That reason just makes no sense at all.

There's only one reason for configuring tabs to be anything but tabs, and that's because someone else set the standard. So if you're editing python or bash, and you don't feel like being a rebel with a cause, you set expand tab.

But obviously you shouldn't be doing that manually every time you open a file, so you should configure Vim to detect what's going on.

You can do that by adding the `ciaranm/detectindent` plugin and then setting the following line:

    autocmd BufReadPost * :DetectIndent
To detect the indentation any time you open a file. That at least for me makes the headache go away most of the time.


Author here.

I literally meant that I enjoy that it will be forced to look the same on every machine. I like that it's not configurable by others.

Personal preference.

Good tip on autodecection!


There's also https://github.com/tpope/vim-sleuth, by Tim Pope.


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.


You'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?


Oh 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.


> 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.


As 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: