Indenting code?

Peter Jensen peter.jensen at oracle.com
Mon Sep 17 18:46:22 UTC 2012


On 09/14/12 12:34, Kelly O'Hair wrote:
> On automatic indenting...  just an experience that might be helpful and some observations
>
> I have used NetBeans when working on JPRT since 2006 at least, updating to each new NetBeans as it came out.
> The "Format" feature is a fantastic feature, but it is a constantly changing feature as it adds features or new options
> every time you tell NetBeans to "Format" it could change the file even though it had  been Formatted in a previous
> version. In addition, the default settings and your project settings on thing like 'spaces in if expressions' or whatever
> can change, and you would have to re-Format all your files if you wanted that new style.
> The source style and format options are a very personal preference
>
> So I only run "Format" when I am making significant changes to a file, BUT, even that can be very painful, if the
> file had not been worked on for a long time, the whitespace changes so overwhelm the diff or webrev that it is very
> hard to see the critical changes in the source file. Telling diff to ignore whitespace changes helps, but at least with
> NetBeans, "Format" will add newlines when you do "Format", so the noise can be significant.

The biggest issue I've had with NB format is that it often undo 
line-folding, and you may end-up with long lines.

I usually just mark-up the lines I'm working on and apply the format to 
the selection. That way the noise is contained to code related to the 
"real" changes.  It's especially useful when you need to change the 
indentation level of a block of code.

Of course, formatting only part of a file may result in inconsistency. 
(It's also a little dangerous, because the same keyboard shortcut does 
the whole file if you forget to select anything).




More information about the discuss mailing list