Alex Rivera | Logout

Best practices for code formatting on large projects

Asked 2009-12-23T21:48:55.547
15

I maintain the build for a large Java EE/Maven/Hudson/Perforce project with about 20 developers spread across the world.

The solution in-place for code formatting is to format the codebase using Jalopy when the developer runs the build, thereby ensuring any code which has not been formatted gets formatted prior to check-in.

The main problem with this solution, is that if the developer doesn't run a full Maven build before checking in (say they run the unit tests from Eclipse) their code won't get formatted. Then, the next developer who edit the file may have many, many diffs in unrelated sections of the code after they run the formatter.

What source formatting strategy has worked best for you on large projects? Another option I had considered is formatting nightly using an automated process.

Edit
Report

2 Answers

2

If all (or most) of your developers are using Eclipse, you can export the formatting rules and save actions to your team's liking and have everyone share the same preferences.

answered 2009-12-23T21:57:12.520
0

If proper formatting is essential to you, then configure Perforce to do its own formatting run on checkin, and tell it to refuse the commit if the formatted version of the source file is different from the one submitted.

Personally we just use Eclipse Save Actions, and tell it to reformat when saving. Good enough for us.

answered 2009-12-24T04:53:15.227

Your Answer