Java – Advantages and Disadvantages of Forced Code Reformat

coding-standardsformattingjava

I'm currently working at a place that may be looking at forcing developers to use an automated code formatter on version control check-in. I'm looking for developers opinions on the advantages and disadvantages of doing this … how you think it would help or hinder developers. My specific case involves Java/JSPs, but I think the question could apply to any language.

Best Answer

I think it's very important to do this. Here's why:

  • It makes your source control diffs show just actual code changes, and all but eliminates "diff noise" due to whitespace and other insignificant formatting choices
  • It makes all code more similar, so that devs are more comfortable pairing and sharing the code bases

If you do it, I would recommend everyone check all code in, then one person does a reformat over the whole code base, then checks it all back in so there's one "giant" change set for formatting (that everyone can ignore), but after that, all diffs are real code diffs.

If you do it bit by bit, you'll be mixing real code changes with formatting changes and things will get unnecessarily messy in change land.

Related Topic