• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Help with indentation

 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

Thanks,
 
Sheriff
Posts: 22800
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

OP is looking for Output Formatting (Indenting) or Indenting the code itself.
 
Campbell Ritchie
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22800
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Master Rancher
Posts: 5005
79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
8 does seem way too excessive. Like Bert, I prefer 2.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Master Rancher
Posts: 5005
79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22800
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right. Let's quit this discussion and get back to the main problem: how to unindent code.
 
Evildoers! Eat my justice! And this tiny ad's justice too!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic