I am working on a Java project, about ten developers in team. And we all use Eclipse as IDE.
To make source code in more consistent style in team, I am wondering if it makes sense to use code formatter template arbitrary? I mean only thing prior to checking in code is to use code formatter in Eclipse.
In general, I know the team will benefit from consistent code style. The problem is – should it works as a force rule? maybe it’s too rigid.
Example 1: The template forces the maximum line width as 80. but it’s ugly if some lines are broken into many lines. sure I know the 80 is configurable.
Example 2: Formatted code by Eclipse:
int green = 1;
int red = 1;
int orange = 1;
My prefer code:
int green = 1;
int red = 1;
int orange = 1;
So my opinion is to use code template, but not rigid, violation to the template is allowable and necessary. What is your opinion about it?
I’d rather create a document that assembles the rules, and get everyone to read it.
The rules are there to be broken, and you not always want your code formatter to automatically do the work for you (in my case this often happens with multiline if statements).
And because you will not always apply to the coding standard, everytime someone uses an automatic formatter, he/she will cause havoc in your git/svn/cvs, changing lines, that actually did not change.
So my advice – don’t use automatic formatting, and convince/learn/force people to write readable code. And make code reviews too!