Is it a good idea to use java auto format in eclipse?

528    Asked by JustinStewart in Java , Asked on Oct 6, 2022

 I use eclipse for coding, and the language which we use is Java. Once it was suggested by someone that to properly format the code, using the auto formatter(CTRL+SHIFT+F) While this command does format the code, sometimes I feel that the overall look becomes weird, and it is not actually very readable.

So is this a recommended thing to do? If not, what is the best way to format our code in eclipse ?

I've found the java auto format very useful. Instead of constantly making microdecisions on how the code should be formatted -- something which is error-prone and causes "cognitive friction" -- you can set up formatting rules and let Eclipse format the code for you (ideally automatically using "Save actions''). Of course, this requires that you have a code base with consistent formatting, or that you have the mandate to reformat the code according to the rules you set up.


Having "auto format-on-save" enabled is a little like having incremental compilation, it allows your brain to stay focused on the code itself, instead of being concerned with trivial issues such as code formatting or syntax.

But yes, sometimes the auto formatter will mess up some nicely formatted table you have. In such cases I use "on/off tags' '. These are configured under the "on/off tags'' tab in the code formatting profile. Using them, you can exclude regions in your code from being automatically formatted:

// @formatter:off

... my nicely formatted table here ...

// @formatter:on



Your Answer

Interviews

Parent Categories