but admit it, tabs are fragile and a pretty weak implementation
but admit it, tabs are fragile and a pretty weak implementation
Could you elaborate? I don't have a personal opinion here and have only worked in orgs that require spaces, but I'm not familiar with the criticisms of tabs.
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.
supertab mode is the tab-to-indent/space-to-align magic.
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!* There's usually a maximum line length restriction as well, so you need to know what the tab-width is to figure out if a line needs to be broken into multiple lines.
* There are also cases where you need exact-column alignment, even across multiple indent widths. A simple example is as follows:
module whatever {
fn long_function_name_whatever(arg1: type1,
arg2: type2,
arg3: type3,
etc: etc4,
do: you,
get: my,
point: now);
}
So in practice, tab width for a project is actually fixed to a particular value. And then you discover that wrong-tab-width code becomes quite annoying to read. I hate reading GNU style guide code, which uses 8-space-tabs but indent-width of 4, because the indenting is unreadable unless I mess with the tab spacing for an individual file I'm reading.But the maximum line length problem is real. I would be 100% for tabs if it wasn't for this issue and imo it's the only real criticism you can make that doesn't have a good solution.
That sounds a lot like a hard limit. The difference between 2-space and 8-space tabs is huge, so you still have to specify what tab width you're using and someone who prefers a narrow tab width could still accidentally blow past the hard limit if they're not careful.
Now, I tend to find it's better to just avoid that kind of alignment in your code style completely (just push the first arg to a new line so you're not space-ing everything out a mile to match the function call open paren) but if that's your style then you can't really do it with actually variable tab widths.
module whatever {
->fn long_function_name_whatever(arg1: type1,
->...............................arg2: type2,
->...............................arg3: type3);
}
It works just fine - tabs for indentation and spaces for alignment.I find that any reasonably complex code with 5 levels of indentation becomes difficult to read, and with more levels the difficulty grows exponentially.
At least with languages I have significant experience, keeping the levels of indentation low never was a problem. But I never did serious amount of coding in LISP or Python, for example, so I don't know if this is practical in such languages.
lets just take the whole idea one step further and either use tools that reformat based on agreed upon styles (meaning a developer could reasonably take the source, preject it into their preferred style and project it back out again).
or store the canonical version as structured data in a database and always project it into some text for viewing.
broader adoption of formatters has drastically reduced the number of pointless and emotional formatting arguments I've gotten into. lets push that further.