|
|
|
|
|
by maxk42
2493 days ago
|
|
My personal preference is tabs and the reason I never hear given is that I simply don't want to press a button two or four times when I can press it once. When I type a single tab: bam! code indented. When I type backspace, the indentation is removed. It's easy. When I'm using spaces -- even in an editor that expands tabs to spaces -- I have to press backspace four times to de-indent code. I end up de-indenting a lot of code because a pet peeve of mine is unnecessary conditionals. For example if you'll pardon the formatting: if(cond) {
flag = true;
} else {
flag = false;
}
can often be represented as just: flag = false;
if(cond) {
flag = true;
}
and in languages that initialize variables, often the first line can be omitted as well.I just feel like I'm stuck in molasses, having to go through several extra steps whenever I'm writing code that compels the use of spaces over tabs. That said: It's a personal preference and I'll use spaces where appropriate. Most people's argument against tabs seems to have to do with vertically aligning code. This is a shit argument, because tabs should be used for indentation only. If your indentation is the proper number of levels then spaces can be used for any remaining vertical alignment. Tabs should be used for indentation, not vertical alignment. Example: tabtabtabtabType myArray[] = {
tabtabtabtabtab 123, 456, 789, 101112,
tabtabtabtabtab131415, 161718, 192021, 222324
tabtabtabtab};
It's not difficult and problems only appear when some n00b tries using tabs between the numbers in the above example to line values up. If you do that you're going to have a bad time. |
|
Newer editors like VSCode handle this correctly. Tab = add 4 spaces, delete = remove 4 spaces.
But really, you should get in the habit of using tab to indent, and shift+tab to deindent (not delete). shift+tab has the added advantage of being able to deintent an entire highlighted block of code in virtually all editors.
> can often be represented as just:
Well, in this case you could just do `flag = cond` but I see your point
> Most people's argument against tabs seems to have to do with vertically aligning code. This is a shit argument, because tabs should be used for indentation only. If your indentation is the proper number of levels then spaces can be used for any remaining vertical alignment.
Well, a lot of people haven't configured their editors to visually see whitespace, and since it is invisible by default, it means a lot of code with mixed whitespace is committed which is a hard problem to solve. So you just configure your auto-formatter to convert everything to spaces so there is no ambiguity.