Get yourself a decent text editor. I usually use Gnome Linux, where gedit works nicely. On Windows try Notepad2 or Notepad++, which are both available free of charge, and much better for programming than what you get with Windows. They will support automatic indentation. Set the options to "replace tabs with spaces" and "tab = 4 spaces." There are explanations in the JavaRanch style guide.
On gedit I use the tab key to start a line more indented than the line above. I can use ctrl-T and ctrl-shift-T to increase or decrease indentation, and there are bound to be similar options in other editors. IDEs can indent everything automatically.
But there isn't an indent character either. Tab is used for it most times but some editors convert these to tabs.
Joined: Aug 16, 2007
OP has used \t ,IMO that means , he is looking for output formatting. But he says indentation, Indentation generally means coding indentation. I never use indentation for output rather I will say output formatting.
[Vishal]: But he says indentation, Indentation generally means coding indentation. I never use indentation for output rather I will say output formatting.
I don't agree with this at all. While code may be the most common place where programmers care about indentation, it's not the only one. Indentation is just one part of formatting, which can be applied to any text, output or input, code or not code.
[Rob]: For your information \t is a tab. It isn't some special indentation symbol.
[Rob]: But there isn't an indent character either. Tab is used for it most times but some editors convert these to tabs.
I assume the last word was intended to be spaces. I'm not sure why it matters whether we call a tab an indent character or not. The original poster said he is using \t for indentation, and that seems simple enough - in most contexts, a leading tab does achieve indentation, whether it's subsequently converted to spaces or not. And I think we all agree that there is no similar way to reverse this, other than removing the character(s) that created the indentation in the first place.
[Campbell]: Set the options to "replace tabs with spaces" and "tab = 4 spaces." There are explanations in the JavaRanch style guide.
Well, the guide doesn't actually say anything about what your tab setting should be. It says use four spaces for the indent level, which is not the same as the tab level. It recommends you don't use tabs at all for code formatting, which I agree with.
However there is a large body of code written by Sun which does use tabs mixed with spaces. This practice is, of course, utterly evil. However it's outside our control. And I find it's useful to be able to browse Sun's source files within my IDE. In order to achieve this, it's best to have your tab set to the same number of spaces that Sun uses, which is 8. This won't affect code we write at all, because our code won't use tabs. But it's nice to be able to read Sun's code too.
Originally posted by Bear Bibeault: 8 does seem way too excessive. Like Bert, I prefer 2.
+1 for 2.
I'll do 4 in the interest of being pragmatic. But 8...? That's just excessive.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Mar 05, 2008
There seems to be a lot of confusion here.
NO ONE is suggesting that you should indent by eight spaces.
I said that you should set your tabs to eight spaces. Meaning one tab is equivalent to eight spaces. Because that's what Sun does. However their indent amount is only four spaces.
When they indent one level, they use 4 spaces. When they indent another level, they use one tab, which is equivalent to 8 spaces. For another level, one tab and 4 spaces, which is equivalent to 12 spaces. Another level, 2 tabs for 16 spaces. And so on.
The tab size and the indent size are not the same thing.
Of course no one outside Sun should mix spaces and tabs, because that's eeevil. (Sun shouldn't either, but I'm assuming it's too late to save them.) I'm not advocating that. I'm just describing what is done in most of the standard library code from Sun.
If you don't work for Sun, then don't use tabs at all in code, and you can set your tab size to anything you want - it won't affect your code at all. But if you set the tab size to 8, it will make Sun's code more readable, if and when you browse it.
And personally, yes, I prefer an indent size of only two spaces nowadays. But that has nothing to do with setting the tab size to 8.