Four seems like a decent tab size. Two is a bit small, eight is definitely too big, and 3 isnt a power of two.

However, I have yet to find someone unhappy with tabbing to the correct level of indentation, then using spaces to set alignment (I actually hate alignment. I also hate "spaces between operators and variables" though. I'm a rebel)

There is a case to be made for mixing tabs and spaces, though: use tabs for expressing the indentation level and spaces for lining things up. Or rather, set up your editor to format the whitespace in this way.

I really gotta say, that does not, in my opinion, improve the readability of the code at all, simply because the brackets are seemingly thrown into a syntax that doesn't make sense. I can understand the logic behind it, but it really does not improve the situation in C or C like languages at all.

End of discussion. 2 spaces is too small, 3 spaces is weird, 5 is too much, 8 is way too much, and hard tabs suck, especially because you'd thing they were 8 actual spaces in one editor, load it up in another, and they'd be 6 or 4 visible spaces wide, and some of the lines wouldn't match.

null1024 wrote:Hard tabs suck, especially because you'd thing they were 8 actual spaces in one editor, load it up in another, and they'd be 6 or 4 visible spaces wide

Why is this a bad thing? If someone who prefers to indent by 6 characters loads your file, they'll see it in their preferred 6 characters. And when they edit it (using hard tabs too, as presumably this would be a company style guide or something) and you load it, all their new code is shown indented by 4 characters, how you like it.

Let the editor take care of the tabs and spaces for you. Vim has the Smart Tabs plugin, Emacs has Smart Tabs code for several languages, IntelliJ IDEA has a "Smart Tabs" option, and GNU Indent can be persuaded with -i99 -ts99 -l999. Works as part of the auto-indentation.

Now look that happens when I open that file written by MacGuyver over there with mixed Tabs and Spaces. Alignment failure. If I wanted to sort through MacGuyvers poorly indented text and I would been an Journalism/Creative Writing tutor and he'd be yet another uselss BA undergrad.

Either uses spaces or uses tabs. If you're going to use tabs, use expandtabs. If you're not, get the hell of my lawn. This is not a democracy. You do not get to choose how many spaces your damn tab equals. Tabs are for socialists and other people who think that other people should be allowed to make ANY choices at all about ANYTHING. In my country, you use a space to indicate a space and that's it!

When you only use tabs to indent and only use spaces for alignment, it will work regardless of your tab size. Unless maybe you have word wrapping on...but if you have word wrap on, you're clearly doin' it wrong.

OOPMan wrote:Any sane individual will go with the latter option because the former involves relying on other people, entities which can generally be shown to most likely to do the WRONG thing.

People make mistakes whether tabs or spaces are used; that's why auto-indentation was invented. (How could you else trust people to indent nested code consistently?)

The problem with spaces is there's no general agreement on how many to use, so the value used by the auto-indentation must be changed from project to project. Tedious. With tabs, the setting is always to emit one tab per indentation level, whether a tab is displayed as two columns or four.

Tabs are used consistently, but displayed differently; spaces are displayed consistently, but used differently.

And again: tabs for indentation, spaces for alignment. It is the auto-indentation's job to distinguish between the two, so you don't have to, just like you don't reformat huge sections of code by hammering the space bar.

1 keypress to adjust indentation, not 475% less file space (for a test sample consisting of 100% tabs equivalent to 4 spaces each)If you use spaces, you hate America. Not just the US, you hate all of America. Even Canada and Mexico and Brazil.

Tabs use ONE character to represent ONE logical entity: An indentation.Spaces use 4 characters and require the use of adjustment macros just to change the indent size.It's like using a package manager... automating the problem instead of fixing it.

Except that you might be using a Thin Client that does not have workable USB, not does it allow you to run random programs. (Though I personally try to stay away from doing anything more than e-mail with those things.)

achan1058 wrote:Except that you might be using a Thin Client that does not have workable USB, not does it allow you to run random programs. (Though I personally try to stay away from doing anything more than e-mail with those things.)

tabs for indentation, spaces for alignment, (like emacs’ smrt tabs linked to above) so would be one of those who get beaten up:but imho indentation is mostly bad coding style:for huge constructors use variables (like kaboutdata. in my example, they indented, but this is not necessary since the arguments are used in the order the variables are assigned)and if you want to create big string lists use text files or databases, don’t mix data with code!

I've also worked on a 1M+ line, 20+ year old software package that is a combination of both C and C++. In it there are mixes of all coding styles, brace styles and indenting styles from an uncountable hoard of programmers using vi/vim/emacs/<inset editor or ide here>.

I've got to say the only way to ensure a measurable amount of readability is to banish all tab characters. At least with spaces it's always consistent. The number of files I found with mixed space/tab indenting was huge, and my general fix was to reindent entire source files using spaces only. Problem solved.

I've got to say the only way to ensure a measurable amount of readability is to banish all space characters. At least with tabs it's always consistent. The number of files I found with mixed tab/space indenting was huge, and my general fix was to reindent entire source files using tabs only. Problem solved.

and still be wrong, since you can retab everything just like you can respace everything.

python is a little bit more difficult (in both directions), but possible, too. your choice is a matter of personal taste.

lulzfish wrote:Tabs use ONE character to represent ONE logical entity: A [single level of] indentation.Spaces use [a variable number of] characters and require the use of adjustment macros just to change the indent size.It's like using a package manager... automating the problem instead of fixing it.

I'm coming in on the side of tabs. The current code base I work on is standardized to use four spaces, and our editors are set to expand tabs to spaces. I hate when I hit the tab key one too many times and I have to hit the backspace key four times to undo it.

Pesto wrote:I hate when I hit the tab key one too many times and I have to hit the backspace key four times to undo it.

Hm, tried shift+tab?

I like to think of indentation as indentation, whether it's tabs or spaces. Use indent and dedent operations in your editor. Then you don't even have to think about tabs vs. spaces. Many editors use tab and shift+tab (typically, you'll need to select some text on the line(s) to make the tab key indent rather than insert a tab). For vim it is >> and << for the current line (and . to repeat) or V, then j/k to select some lines, then just > and < (again, . to repeat). Using = (or == for a single line) will indent correctly according to brackets. All good editors will do this for you. Except ofc in Python

Why does everyone claim 8 is too much? Assuming the average length of a line is 40 characters (an overestimate, IME), and you want to avoid going over 80 characters (although for some lines, it might happen), that gives you 40 characters of indentation. 5 tabs. If you're nesting any deeper than that, you're screwed anyway. Whereas people who use 4 spaces think it's ok to do 10 levels of indentation, and people who use 2 (which appears to be the emacs default for some languages) think it's ok to do 20 levels...