At least in C, I like to line things up sometimes:
void function_with_lots_of_arguments (int arg_a,
int arg_b,
int arg_c);
If I was to use tabs and someone had a different tab width to me, they might end up with: void function_with_lots_of_arguments (int arg_a,
int arg_b,
int arg_c);If you're trying to line things up with tabs, you're doing it wrong. Tabs are for indentation. Lining up columns is not indenting. (I'd also argue that trying to line stuff up like that is, nine times out of ten, doing it wrong: it inevitably leads to an if statement where the consequent is indented as much as the last line of conditions. If people are swearing by a style guide that says "always do this," and it's that, at least some of their code will end up being messy anyway).
In this case you use spaces for the parts that shall be lined up and tabs for the rest. Example:
class Foo
{
\tint bar(int a,
\t int b);
};
Re:Poll: Spaces or tabs?
by cheradenine01 on Saturday February 02, 2013 @03:01PM
(#5157111)
Yes, but you can't tell in your editor if you've got
\t int b);
or
\t\t int b);
Because they'll look the same to you, but not to anyone else without 4-space-tabs.
That is correct. But you do know the indentation rule so you know that the int b only has 1 tab followed by spaces.
There are editors that have such a feature (for example called "show whitespace" or "show spaces and tabs").
Re:Poll: Spaces or tabs?
by markokocic on Saturday February 02, 2013 @11:26AM
(#5156367)
That's where one single rule helps: use only tabs for indentation and only spaces for alignment.
I have vim configured with 4-space tabs, but less(1) on my box uses 8-space tabs. I could reconfigure everything on my box to use 4-space tabs but it's easier to just have vim save tabs as spaces.
If I type with 4-space tabs:
username admin
port 22
importance 3
And then print it with 8-space tabs: username admin
port 22
importance 3
but if I had saved the tabs as spaces, it would still line up.If your team has more than one person in it, you have two choices for indentation:
You can use spaces only, or you can have a random invisible mish-mash of tabs and spaces.
Nobody EVER gets it right, and if you're coding in something whitespace-sensitive, you're in for a wild ride.
Nor why style guides recommend it.
Any one have a good reason?