CodeQuality

From AardRock Wiki
Revision as of 07:51, 25 April 2006 by Roderik (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Code Quality

To keep the code readable, understandable and maintainable, please try to keep to the following guidelines:

  • Run the formatter before you commit to SVN.
  • Don't catch Exceptions and print their stack trace. [wiki:ExceptionLogging Log them instead.] Consider what would be the right place to catch them.
  • Prevent Exceptions instead of catching them, if possible. For example:


public static String getExtension(String filename) {
 int index = filename.lastIndexOf('.');
 if (index >= 0) {
   return filename.substring(index + 1);
 } else {
   return null;
 }
}


is preferred over:


public static String getExtension(String filename) {
 try {
   return filename.substring(filename.lastIndexOf('.') + 1);
 } catch (IndexOutOfBoundsException e) {
   return null;
 }
}


  • Use the [wiki:EclipseDebugger debugger] to debug.
  • For headless things, write tests. (Headless = without graphical user interface.)
  • Write tests first.
  • Don't confuse Boolean with boolean: the former is a class, the latter a primitive type. This is an example of how not to do it:


Boolean b = true;