Skip to content

Coding Standards

Michel Jung edited this page Nov 6, 2018 · 9 revisions

Within a group of developers working on the same projects, it is important that everyone follows the same coding standards. This page aims to document Java coding standards for Forged Alliance Forever as briefly as possible.

We try to detect and report as many violations with Codacy, though not all are possible. This list is being extended as violations are found during reviews.

Exception handling

Logging

Always decorate placeholders

When logging values, always decorate placeholders to distinguish them from normal words.

Noncompliant Code Example

// Noncompliant - placeholder not decorated
logger.warn("Attribute {} has not been set", attribute);
  • Produces Attribute name has not been set for attribute = "name", in which case we don't know if "name" is part of the sentence or if it's a value.
  • Produces Attribute has not been set for attribute = "", in which case we don't see that there's an empty value being logged.

Compliant Solution

logger.warn("Attribute '{}' has not been set", attribute);
logger.warn("Attribute has not been set: {}", attribute);
  • Produces Attribute 'name' has not been set or Attribute has not been set: name for attribute attribute = "name", which makes it clear that "name" is not part of the sentence but a value.
  • Produces Attribute '' has not been set or Attribute has not been set: for attribute attribute = "", which makes it clear that there is an empty value.