Skip to content

Instantly share code, notes, and snippets.

@kofemann
Last active August 9, 2017 10:28
Show Gist options
  • Save kofemann/247c6e0953e706292d3978ad9073ae47 to your computer and use it in GitHub Desktop.
Save kofemann/247c6e0953e706292d3978ad9073ae47 to your computer and use it in GitHub Desktop.
dCache code guideline

dCache code guideline

Spaces vs Tabs

dCache projects uses four (4) spaces indention. Some historic code still have mixed style. However, the newly written code must stick to spaces.

Variable names

Before IDEs got widely used and syntax highlighting become mature, class field members was prefixed with underscode, like _aClassMemberField, to help developers to separate member fields from method's variables. Today this is not necessary any more. However, when an existing code is modified, the file's existing style must be used.

Legacy code:

class A {
   private _field;
}

New code:

class A {
   private field;
}

Logging

dCache uses slf4j logging library as the main log facility. The logger have to be defined as:

public static final Logger LOGGER = LoggerFactory.getLogger(clazz);

toString() method

Most of the classes will override Object#toString() method. Use guava's MoreObjects.ToStringHelper

    @Override
    public String toString()
    {
        return MoreObjects.toStringHelper(this)
            .add("ctime", _ctime)
            .add("creationTime", _creationTime)
            .add("atime", _atime)
            .add("mtime", _mtime)
            .add("pnfsId", _pnfsId)
            .omitNullValues()
            .toString();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment