This discussion was originally a part of a longer discussion that has been moved to Tech:Zipped topic content
Another thing, I have a few comments on the code style... while mostly I agree on the code style you described on the contributions page, I do have a few objections. First, tabs are not everybody's friend... you will never get a tabbed java source code align correctly with any other tab size than the original tab size of the author... and at this point the advantage of the tabs are gone. Believe me, I have experience with this one. Where I work we are a few developers with different coding style preferences, and in the beginning we had big fights about code style... now we settled down on the following principles:
These work remarkably well for us... and believe me, at the beginning we did have some wild re-re-reformatting wars ;-)
Cheers, Csaba 28-Nov-2006 06:40 PST
PMD send nice warnings. There is one rule I'd like to discuss though: OnlyOneReturn
A method should have only one exit point, and that should be the last statement in the method. This rule is defined by the following Java class: net.sourceforge.pmd.rules.design.OnlyOneReturnRule
According to this rule
private static File retrievePropertyFile(String filename) {
File file = null;
try {
file = Utilities.getClassLoaderFile(filename);
return file; //there should not be an exit point here
} catch (Exception e) {
// file might not exist
}
try {
file = new File(Utilities.getClassLoaderRoot(), filename);
return file; //oops yet another exit point
} catch (Exception e) {
logger.severe("Error while searching for resource " + filename, e);
}
return null;
}
should be
private static File retrievePropertyFile(String filename) {
File file = null;
try {
file = Utilities.getClassLoaderFile(filename);
return file;
} catch (Exception e) {
// file migh tnot exist
try {
file = new File(Utilities.getClassLoaderRoot(), filename);
} catch (Exception e1) {
logger.severe("Error while searching for resource " + filename, e1);
}
}
return file;
}
What do you think? I think this rule is rather controversial and would be in favor of totally disabling this rule.
// good version
public String processArg(String arg) {
String result = "something";
if (arg == null) {
return result;
}
// do something with arg
if (!testArg(arg)) {
return result;
}
// do more stuff...
return result;
}
// PMD "single return version
public String processArg(String arg) {
String result = "something";
if (arg != null) {
// we could have returned if null
// do something with arg
if (testArg(arg)) {
// we could have returned if failure
// do more stuff...
}
}
return result;
}
To ensure valid XHTML during development is a very hard task. Maybe you should try to use a tool like this servlet filter in the development phase:
One of the oldest wars in programming circles is whether tabs or spaces should be used for indentation. The Linux Kernel coding standard says tabs, the Java coding standards say spaces. Until recently I've been in the "tabs" camp and as a result the JAMWiki standard is tabs, but the job I'm working on now requires spaces, and I've found that modern editors make that far less evil then it used to be... so, does anyone have a preference? There's one vote for spaces instead of tabs above, and I'm the middle. If enough people prefer spaces to tabs I'm amenable to changing the project standard, otherwise we'll just stick to tabs. Speak now or forever hold your peace. -- Ryan 14-Jul-2007 17:20 PDT