Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with indentation

 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using \t for indentation. How to acheive the opposite(un indent)?

Thanks,
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For your information \t is a tab. It isn't some special indentation symbol.

You can try to use \b (backspace), but unless you then overwrite that character it will still remain.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50242
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

OP is looking for Output Formatting (Indenting) or Indenting the code itself.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50242
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vishal Pandya:

OP is looking for Output Formatting (Indenting) or Indenting the code itself.


Sorry, I have misunderstood the question. ( ) I don't think there is an out-dent character.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But there isn't an indent character either. Tab is used for it most times but some editors convert these to tabs.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Anyways he got answers in both context.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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.

As for the side topic of Java style:

[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.
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
8 spaces always seemed excessive - i prefer 2 and i understand that that's probably too lean for a lot of people - if I worked on a team I'd vote for 4...

but why 8? (seems like a waste of pixels)
[ December 21, 2008: Message edited by: Bert Bates ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
8 does seem way too excessive. Like Bert, I prefer 2.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. Let's quit this discussion and get back to the main problem: how to unindent code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic