by gregmac · 5y ago · 0 comments
Consider the following code:
if (x)
{
SomeMethod(paramater1,
paramater2,
parameter3);
}
If done "properly", it is: if (x)
{
<tab>SomeMethod(paramater1,
<tab><spaces...>paramater2,
<tab><spaces...>parameter3);
}
What I often see, that totally breaks the entire point of tabs: if (x)
{
<tab>SomeMethod(paramater1,
<tab><tab><tab><space><space>paramater2,
<tab><tab><tab><space><space>parameter3);
}
The same thing happens if you are trying to align table-style code: var badMixedTypeArrayExample = [
[ "some", true, 128, x ],
[ "long strings", true, 8, someLongVariable ],
[ "and", false, 16384, x ],
[ "short", true, 12345678, anotherVariable ],
];
If tabs are used between fields, it will look like a hot mess to anyone with a different tabstop than the author.Either use spaces everywhere so you have total control over the layout or forego alignment (other than block indentation). Mixing tabs and spaces is a path to madness.
I have F11 in emacs bound to whitespace-cleanup, which takes care of it all for me. And supertabs mode in general works just the way it should with tabs-indent/spaces-align.
Then there's also clang-fmt, possibley used as a post-receive hook in git (and some other VCS) which makes irrelevant what the programmer's editor did, mostly.
if (x)
{
SomeMethod(paramater1,
paramater2,
parameter3);
}
You simply should not write this code. It's unclear, and performs nonsense indentation. You could do: if (x)
{
SomeMethod(
paramater1,
paramater2,
parameter3
);
}
If you need your function to use line breaks.I've also seen a lot of SQL and LINQ (C#) written in this way, as well as things like:
var longString = "Line 1\n" +
"Line 2\n" +
"Line 3";Setting up an automatic formatter and using tabs is personally the best for all worlds. Space-like alignments like
var someReallyLongVar = 5;
var x = 10;
Are the worst!