5 ms·
For me the problem happens as soon as tabs are used for alignment, instead of just indent. The benefit of tabs is custom tabstop. If anyone does anything that u
by gregmac 5y ago
For me the problem happens as soon as tabs are used for alignment, instead of just indent. The benefit of tabs is custom tabstop. If anyone does anything that undermines that benefit, you might as well use spaces to avoid all the problems caused.
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.
- cool_scatter 5y agoWhich is the reason for the very common stance "tabs for indentation, spaces for alignment".
- nybble41 5y agoWhich is easy to say, but hard to make everyone do correctly. First you need to ensure that everyone uses an editor with a "visible whitespace" option, and turns it on, so they can see whether they have the right whitespace. Then you get to spend precious programming time turning one kind of whitespace into another since most editors will get it wrong when they auto-indent. 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.
- PaulDavisThe1st 5y agoThis is part of the reason why editors for programmers and editors for general text editing are not the right thing. 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.
- comex 5y agoCan whitespace-cleanup really differentiate between places where you want a tab for indentation, and places where you want spaces for alignment, where the number of spaces may be greater than the tab width? After all, the only way to differentiate is to guess what you might be trying to align to by looking at surrounding lines… but from a quick search, whitespace.el looks less complex than that.
- PaulDavisThe1st 5y agoYou're entirely correct. Sorry, i forget, whitespace-cleanup is there so that I can remove dangling whitespace from the end of lines. supertab mode is the tab-to-indent/space-to-align magic.
- zkldi 5y agoif (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.
- gregmac 5y agoI totally agree; I personally hate this style of code! However, people still write it (in the same way they screw up tabs+spaces), and in some code bases it's "the style" they use. 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";
- zkldi 5y agoPersonally, I'd go as far to say that `alignment` is an anti-pattern. 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!