6 ms·
= Why Grown-Ups Don't Use Tabs = * Joe likes 4-space tabs, I like 2-space tabs, and Jane is old-school with 8-space tabs. * All goes well until someone aligns
by inanutshellus 9y ago
= Why Grown-Ups Don't Use Tabs =
* Joe likes 4-space tabs, I like 2-space tabs, and Jane is old-school with 8-space tabs.
* All goes well until someone aligns something visually, like so:
void someNiceMethod(
[tab][tab][tab][tab][space][space]int myParam...);
* Now it aligns perfectly on my machine, looks mostly ok on Joe's machine, and is ON MARS on Jane's machine.
Thus one-or-more of three futures happens:
* Someone implements a code re-formatter into version control
* Someone re-aligns the code, starting the process over again.
* Someone calls a meeting and demands we all switch to spaces
- menssen 9y agoThere's actually a solid argument for "tabs for indentation, spaces for alignment", which solves both for preference and vertically aligning stuff: [tab]void someNiceMethod( [tab][space*20]int arg1 [tab]) But it basically requires having some visual indicator of what is a tab, which most people don't like. (edited for line breaks)
- rplnt 9y agoI like how it is in Sublime (2) - it shows whitespace characters on highlight.
- IshKebab 9y agoThat's pretty nice. VSCode has a pretty good option too that shows whitespace except single spaces between non-whitespace characters.
- 0xffff2 9y agoI have visual whitespace turned on in all of my text editors. The massive amount of mixed tabs/spaces and trailing whitespace I find in virtually every document with multiple authors leads me to believe that I'm the only person on the planet who actually cares about whitespace at all.
- mark-r 9y agoTrailing whitespace drives me batty! The only reason I can come up with for it is sloppiness.
- emddudley 9y agoIf a system requires thought and care to be used properly then people will inevitably use it improperly. Even skilled, thoughtful people make mistakes or get fatigued and take shortcuts. It seems to me that using tabs for indentation and spaces for alignment is a fragile technique. It's easy to make a mistake and not even notice. If you don't fix that mistake fast, people start to assume that maybe it's OK to ignore whitespace formatting issues. And so the problem compounds. I would prefer to use a system that creates a "pit of success" so that even careless people have a hard time doing it wrong. I think sticking to just one whitespace character is better than mixed tabs and spaces, but best of all is using an editor that can automatically format your code.
- menssen 9y agoWhat I didn't say in my original comment is that I don't actually do this for exactly the reason you describe, and that I think spaces-only is the most robust solution. That said, all you would need is editors to enforce "any line with spaces before a non-whitespace character must have exactly the same number of tabs as the previous line." Which would not be all that difficult, but currently (afaik) does not exist.
- frobozz 9y agoWho aligns like that? It seems to defeat the purpose of putting it on a separate line. void someNiceMethod( <tab>int myParam... ); Hey Presto! You, Joe and Jane all get your preferred size size of tab. As a bonus, this indentation style works equally well if Jim uses a non-fixedwidth typeface.
- rootusrootus 9y agoWell, as long as everyone always use tabs, that should work out okay. But in practice, of course, it doesn't ever happen that way. Nice thing about a space is that it is always a space, a tab is however many spaces you personally want it to be.
- metaobject 9y agoNon-fixed width typeface? That would be grounds for immediate termination.
- IshKebab 9y agoYou'd lose a pretty good employee then: http://www.stroustrup.com/3rd_notes.pdf http://www.stroustrup.com/3rd_notes.pdf > At first glance, this presentation style will seem ‘‘unnatural’’ to programmers accustomed to seeing code in constant-width fonts. However, proportional-width fonts are generally regarded as better than constant-width fonts for presentation of text. Using a proportional-width font also allows me to present code with fewer illogical line breaks. Furthermore, my experiments show that most people find the new style more readable after a short while Great book, and I have used proportional fonts occasionally. It's much much better than you might imagine (as long as you are sane and use tabs for indentation). Obviously you can't get "perfect" alignment like you can with fixed-width fonts, but it is certainly nicer to read, so there is a trade-off.
- saghm 9y agoDo people actually code with non-monospaced fonts? I've never seen anyone doing that before
- 9y ago
- blktiger 9y agoYou mean something like this don't you? [tab]void some nice method(int param a, [tab] int param b So long as you only use tabs for indentation, not alignment, tabs look correct on _everyone's_ machine. The real problem with tabs is that (some) people are lazy and do stuff like this: [tab]void some nice method(int param a, [tab][tab][tab][space][space]int param b Personally, I think if you work like that you need to learn to be professional and write code that follows whatever coding standard your organization uses. If they use tabs, the second example is _not_ following the coding standard. So whether to prefer tabs or spaces, to me, depends entirely on how much you can/want to trust your coworkers to follow the coding standards. Edit: Or as pointed out below, change your coding style to this: [tab]void some nice method( [tab][tab]int param a, [tab][tab]int param b
- city41 9y agoWhile this is true they will look correct on everyone's machine, they'll be annoyingly wide in tools that display tabs as 8 spaces (such as less, most online diff displays, etc). But spaces will look the same regardless of tool, editor, anything.
- pera 9y agoI don't know what online diff do you use, but less let you configure the tab stop with the -x option, which is the point of using tabs: being able to chose what's more readable for you.
- jasonkostempski 9y agoThe only reason 2, 4 or 8 is less "readable" to anyone is because they have a mental breakdown when they see a style they don't prefer and can't get past it. Tab is a variable width character, it has no place in text laid out with fixed-width fonts.
- pera 9y agoIs having a style preference bad? One can freely configure color scheme and font, so why should indentation be restricted?
- qb45 9y ago> * Joe likes 4-space tabs, I like 2-space tabs, and Jane is old-school with 8-space tabs. > * Someone calls a meeting and demands we all switch to spaces They compromise on the average 5 spaces per tab and everybody is dissatisfied.
- pasquinelli 9y agosee, i just think that's why grownups don't do that shit. you've got something that would normally be on one line but it's too long? indent once extra and don't be weird. there's no value in lining it up with the parenthesis.
- jpfed 9y ago>All goes well until someone aligns something visually, like so: I have been programming for most of my life, and I still don't know why people do this. I just don't feel the need to align stuff.