Coding Guidelines describe the guidelines of code contribution for the Contributors and Committers.
This is a living document and is still being discussed on the Wink mailing lists. Please feel free to discuss and modify the guidelines.
- The project must keep backward compatibility between minor versions, unless the change is required to fix a bug.
- The project should keep backward compatibility between major versions, if possible.
- In order to reduce amount of potential backward compatibility problems, follow the following guidelines:
- Expose as few APIs as possible to user.
- Prefer exposing interfaces to exposing classes.
- An internal class, must have the internal word in its package name (e.g. org.apache.wink.internal)
- Remember: it's always possible to move a class from internal package outside, but it's never possible to move the classes to internal, after they were released.
- Classes that are exposed to user only by their class name (e.g. servlets, listeners, spring beans) should be located in the internal package. However, they must contain a javadoc clarification that their name must not be changed.
Potential Programming Problems
- Never call methods that can be overridden by a subclass from the constructor.
- If you call any method from the constructor, either declare the whole class final.
- Or make method private, or final, or static.
- Exceptions Handling
- Checked Exceptions
- Handle checked exceptions when possible.
- In case the exception cannot be handled, allow it to propagate to the calling method by declaring "throws".
- If the method's API cannot be changed, wrap the original exception with WebApplicationException. Important! Never wrap unchecked exceptions with WebApplicationException!
- The InvocationTargetException should always be handled. Consider using the following pattern:
- Unchecked Exceptions (Runtime Exceptions)
- Don't catch unchecked exceptions unless you can handle them properly.
- Be aware of "catch (Exception e)" statement, since it also catches unchecked exception. If there are multiple checked exceptions that should be handled in the same way, consider using the following pattern:
- Checked Exceptions
- In general logging is a good idea.
- Use Slf4j.
- For debug messages, call
if (log.isDebugEnabled())prior to calling
- The following code is usually bad. There is no need to log exception and re-throw it: Either log it, or re-throw.
- Messages which are visible to the end user should have their strings externalized and read from a properties file to allow for easier NLS translation.
- Debug messages do not need to be put into a properties file.
In a perfect world all people, who contribute code, use the same IDE with the same formatting preferences which, for example, significantly reduces a number of redundant SVN merges.
- An Eclipse code style is attached to this page: wink-eclipse-codestyle.xml Code contributions may use other format styles but please try to use at least the following rules.
- Anyway for people, who don't use Eclipse, or want to keep their formatting preferences, let's define some basic rules:
- Do not use Tab. For indentation use only spaces. Indentation size is 4 spaces.
- Maximum line width: 100 characters.
- All Spring bean names must start with "wink".
- Do not use dots in the bean names, since it may effect some spring functionality (e.g. util:property-path cannot be used with dots)
- Add "internal" to the bean names that should not be used by the user.
- When using PropertyPlaceholderConfigurer use the following guidelines:
- The "order" property should be set between 1 and Integer.MAX_VALUE. I would suggest setting it somewhere around Integer.MAX_VALUE/2 to ensure that anyone can insert a PropertyPlaceholderConfigurer both before and after.
- Set "ignoreUnresolvablePlaceholders" to true, to ensure that Wink won't fail because of others placeholders.
- Create a unit test, which will hold a validating PropertyPlaceholderConfigurer (ignoreUnresolvablePlaceholders=false) to ensure that none forgets to resolve a placeholder.
- All properties must start with "wink".
Note: It's not yet decided if Ant or Maven or both will be used for building.
- All plugins/dependencies versions must appear only in the parent pom under the plugins/dependencies management. The examples (samples) may be exception to this rule, since they may contain additional dependencies.