4 ms·
The common argument is that with spaces the indent is the same in not only every editor, but also every tool used, such as cvs, diff, patch, build tools, web vi
by Freak_NL 10y ago
The common argument is that with spaces the indent is the same in not only every editor, but also every tool used, such as cvs, diff, patch, build tools, web viewers (e.g., for your cvs tool, issue tracker, and/or code review), shell tools (e.g., less and cat), et etcetera.
With tabs you need to configure each and every tool you use to use the right indent (2? 4? 8?), with spaces, every tool just works, and copy/pasting a section of code to or from an issue or an e-mail or a chat tool just works.
It is a matter of code typography. When more than one developer is working on a code base, it helps if every one sees the same outline, because with varying amounts of indenting one persons preference aligns all parameters in a long important method call, whilst any other indenting breaks (part of) that format — code may look fine for one person, but jumbled for another with a different indent preference.
With editor support better than ever, using spaces isn't something you think about when coding; you just hit tab to indent and it inserts the number of spaces configured.
I like Python's PEP 8 in that respect. The language itself (and the syntax checking tools such as pyflakes) simply states the sensible default you aught to be using.
- scrollaway 10y ago> With editor support better than ever, using spaces isn't something you think about when coding; you just hit tab to indent and it inserts the number of spaces configured You mean like those times I would have to configure my editor so it inserts the exact amount of spaces required by the project I'm working on, for the project maintainers prefer 4-width to 2-width or 8-width? :) You talk about typography but this is exactly what I underline in my article: Your preference is not everybody else's and I personally find 2-space code absolutely unreadable... while some companies adopt it as their internal codestyle. My eyesight has been deteriorating for the past 10 years and I've had to increase my font and zoom sizes as well as line spacing every now and then. Compact 2-space code truly is a strain on the eye for me. If you're using tabs, you don't have to care about my eyesight, just like you don't care about my font size.
- Stratoscope 10y agoIf you're interested in another view, see scrollaway's code example linked above, along with my other comment in this thread that links to a couple of my previous discussions of the topic. In short, the real issue with tabs is that you can't reliably use them for column alignment. But many of us have concluded that column alignment is a harmful practice, preferring indentation instead to show the structure of our code. And once you give up column alignment, you can use tabs for indentation, and it just doesn't matter what tab size the person reading your code prefers. It will read just the same in any tab size and any font, even proportional fonts. It's really quite liberating to stop using column alignment. :-)
- minitech 10y agoIt's been mentioned elsewhere, but I figured I'd emphasize it here, given > And once you give up column alignment, you can use tabs for indentation You don't have to give up alignment for tabs if you like it occasionally; just indent with tabs and align with spaces. (I highlight leading spaces in a slightly different shade from the background to allow for this.)
- mrcsparker 10y agoWith tabs, everyone gets to use their own indent. It is a lot more portable from programmer to programmer.