Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 34 Next »

Your Rating: Results: 1 Star2 Star3 Star4 Star5 Star 3 rates

Also see Naming conventions.

Code style

Magnolia contributors are kindly requested to follow these simple conventions below:

General Style


  • Tab policy: spaces only (warning)
  • Indentation: 4 spaces
  • Maximum line width: 120 (no strong rule here - don't put exceptions declarations on new lines just to respect this, for instance)


  • We preferably don't use abbreviations in classnames (only exception to that rule is MgnlSomething)


  • Single-line if-statements: we always use curly braces
  • Unnecessary else-branch: if the else is not necessary (e.g. because if-branch always returns or throws an exception) we omit it


  • for optimal refactoring support we use the @Override for all methods that override methods declared in superclasses/implemented interface
    • Hint: you might want to adapt compiler settings of your IDE to show Errors on missing @Override's (Eclipse and Idea provide that option)


  • if you come across a //$NON-NLS-1$ please just delete it - that's legacy stuff created by Eclipse - we don't want to keep that!


  • Always ensure that you have the right license headers in place !
  • Class-level documentation is mandatory.
    • we do use @version $Id$
    • we don't use @author tags any longer as we're usually not interested in the one who had create the file (SCM could tell
      you if required)
    • @author can however be added as a "recognition" mark for external contributors
  • @deprecated must include since: e.g. @deprecated since 4.0
  • First sentence of any Javadoc comment must finish with punctuation. (This is/was needed for summary pages/tables to include the first sentence next to the described element)
  • DRY.
  • See
 * Sample showing how a proper Javadoc comment should look like.
 * @version $Id$

The $Id$ variable will be replaced by svn's keyword substitution: e.g.

 * @version $Id: 41135 2011-01-06 18:12:01Z dlipp  $

See the file attached for Eclipse Preferences (which you can simply import and everything should be done).

Preferences>Java>Code Style>Code Templates>Automatically add comments... is not used as there are different headers for the different editions. The alternative is ... (todo)

Style of JUnit-Tests

With Magnolia 5 we witched to JUnit 4. As it is fully backwards compatible this does not enforce you to write your tests in the new v4-style (e.g. use @Test, @Before etc.).

We set up the following rule:

  • all new test will be written in JUnit 4 style
  • existing tests can/should be updated if you're touching them anyway
  • existing superclasses for tests (especially in core) cannot that easily be updated as there might be lots of subclasses affected by that change. We'll lift them to v4 style in a consolidated action (see MAGNOLIA-3655)


We don't explicitly set serialVersionUID's as we don't want to decide ourselves when these id's should be updated. We rely on the JVM doing that for us (being aware that this id's could potentially differ from JVM to JVM). IF for any (valid) reason, such an id would be needed for a given class, the reason needs to be documented in the code. Failing that, there's a good chance the field will be removed by a fellow zealous developer.

  • No labels