6 ms·
I see a few arguments here which suggest people think tab-users might care less about their code and/or their fellow coder. As someone who slightly prefers tabs
by GavinAnderegg 9y ago
I see a few arguments here which suggest people think tab-users might care less about their code and/or their fellow coder. As someone who slightly prefers tabs and abhors mixing of tabs/spaces, I find this frustrating.
I generally prefer tabs because I feel that they're more egalitarian: I like 4-space indentation, but don't want to force that on everyone encountering my code. Similarly, I find 2-space indentation very hard to parse in most languages, so I don't want that affecting me if I can get away with it. While this is possible with spaces and maybe a series of Git hooks, it's trivial with tabs.
On the other hand, I always use spaces in languages like Python or Ruby where there are well-codified style standards. I also always show invisible characters on any editor which allows it, and have cleanup scripts to ensure that whitespace is standardized across any non-vendor code in the project.
Maybe most tab users don't feel this way? Maybe most aren't as careful/picky as I am? Maybe tabs are more popular with younger devs? But I feel like tabs can offer more interoperability than spaces when many coders are working on the same project when the language/community doesn't strongly specify whitespace.
- leblancfg 9y ago"As someone who slightly prefers tabs" ... "I generally prefer tabs" wat
- GavinAnderegg 9y agoI generally prefer tabs, but I don't use them when writing Python (which is most of my job these days). I'm also not all that hung up about it, so I started with "slightly".
- justin_vanw 9y agoWell assuming correlation implies causation (always safe), enjoy being poor.
- pyre 9y agoSome things are more important than money. Let this tab-idealist enjoy a tab-ful life in the way that they see fit.
- GavinAnderegg 9y agoHonestly, I'm not even that much of an idealist. I think using the same indentation style as the general community is important, so I use spaces most of the time day-to-day. My biggest point was: maybe we don't need to berate/assume things about others for having different preferences than us?
- GavinAnderegg 9y agoI can assure you that I'm not poor ;)
- fragsworth 9y agoI agree with you and kinda wish people would take a combined approach. Tabs are better for indentation preferences. Spaces ensure that everyone sees the same thing, which can help in multi-line situations. So I wish people would avoid this black-and-white discussion. Use tabs for indentation, and spaces for multi-line alignment...
- woodrowbarlow 9y agowait, but that defeats the purpose of both, right? if you change the width of your tabs, then the hard-spaced multi-line parts will no longer align.
- zeveb 9y agoNo, your editor just inserts as many tabs as the initial line had, then spaces over appropriately. This will align properly with any tab setting. I think the real problem with tabs is that so many people use weak editors.
- sofal 9y agoIt would be ironic to use tab characters as some kind of magnanimous concession to other developers' preferences while at the same time requiring them to drop their editor of choice.
- okdana 9y agoThey mean like this, where `-` is tab and `.` is space: --def myfunc( ---foobar = 1, ---...baz = 2 --) (silly example, idk, you get what i mean) No matter what size tab stops you use, the `=` will always line up vertically, because the tabs are only used for the indentation (nesting level), not the visual alignment.
- chaosfox 9y agoyeah, reading this entire thread shows why spaces is more popular. nobody knows how to use tabs properly.
- 9y ago
- tbabb 9y agoUsing tabs has the opposite of your intended effect: If there is any text which is vertically aligned beyond the first indent, then this alignment will break for anyone who doesn't have your tab width preference. They're then forced to change their editor settings to view your file in a non-broken way. I get way more pissed about someone else "forcing their preferences on me" when this happens than when I run into a tidy, 2-space-indented file. If you configure your editor to drop spaces when you hit 'tab', then the file is guaranteed to look the same for everyone, and stops being context-dependent-- a bad thing for plain text, IMO.
- agrajag 9y agoYour issue is why you see people say "tabs for indentation, spaces for alignment." If you're trying to vertically align text, use tabs to keep it at the same indentation as the thing you're aligning to, and use spaces to adjust to vertical alignment. This will keep the vertical alignment regardless of the preferred width of the tab.
- tbabb 9y agoSo for long lines to move an argument over to align with its predecessor on the previous line, like int f() { int someVariableName = myFunctionCall(expr(5), // <--- line A somethingElse(9), // <--- line B a_long * expression + involving(multiple.subExprs)); int d = somethingElse; // <-- line C } ...you're saying line A is indented with tabs, and line B with spaces? Because that will misalign if your tab setting isn't the same. Or are you saying that both A and B are indented with spaces? Then what about line C, which will misalign with A and B if your tab stop is a different width? Or do we indent the entire body of f() with spaces, and then in that case you're basically using spaces everywhere, which the good idea that sparked this whole thing?
- deleted 9y ago[deleted]
- 9y ago
- lmm 9y agoI think tab users are naive, misguided idealists rather than people who made a deliberate choice to screw over their fellow devs, sure. Tabs do indeed seem like they ought to be "more egalitarian" as you describe. It just doesn't work out that way in practice; it ends up more exclusionary because you wind up with a codebase that you can only work on if you have particular tabstops set up, rather than one that you can at least edit in any editor.
- GavinAnderegg 9y agoThis is another style thing, I think. When writing Objective-C I always use spaces because lining things up is idiomatic to the language. Same with Python which has well-codified rules for many multi-line argument lists and the like. However, beyond that, I don't tend to line up assignments or anything else that has me doing "special indenting", so (at least with my code) this doesn't end up being an issue. If I was working on a project where there was a strong preference for indenting assignments, or any other case like this, I would use spaces throughout.
- olau 9y agoYou are clearly being thoughtful, but the problem with tabs and mixing them into code is that when multiple people write the code, some spaces are going to slip into that tab heaven, and then indentation will break for someone. So by choosing tabs, either the file must be consistently formatted with tabs by everyone always, or everyone must look at the code in the same editor configured in the same way always. I remember reading jwz's rant on this long time ago and not getting it until I had the first what-is-going-on-here moment due to wrong indentation from mixed tabs and spaces. jwz is right. Stop using tabs.
- GavinAnderegg 9y agoI'm honestly not that worked up about tabs/spaces, I just get frustrated when I see people assuming those indenting with tabs are careless or anti-social. I only indent with tabs on projects where I have control over the style standard. About your argument, though: Isn't is also possible for someone to copy/paste something with tabs into space-indented code? Isn't is also possible for someone's editor to start off with tab-based indentation by default instead of space-based and mistakenly add the wrong whitespace to the project?
- vidarh 9y agoMy main reason for preferring spaces is that I have yet to work in any context where tabs occurred where it did not end up with mangled formatting sooner or later. Yes, often because it ended up being mixed with spaces, accidentally or intentionally, but nevertheless it seems to me to end with someone making a mess of it. If everyone used tabs perfectly, I'd be fine with them...
- GavinAnderegg 9y agoIsn't is also possible for someone to copy/paste something with tabs into space-indented code? Isn't is also possible for someone's editor to start off with tab-based indentation by default instead of space-based and mistakenly add the wrong whitespace to the project? As I've said in other parts of this thread, I'm not that worked up about tabs vs. spaces, and I use spaces most of the time. I just don't find this argument for space superiority very convincing. PS: If everyone showed invisible characters in their editors, I think the world would be a better place.
- vidarh 9y agoA decent editor can be configured to convert those tabs to spaces on paste. And if you stick to only spaces it is trivial to reject tab containing code in commit hooks. It's harder to reject code that uses spaces wrong in tab-indented code, unless you outlaw spaces for alignment too.
- deleted 9y ago[deleted]