Home SF Project Home

Gridarta Development Documentation: Code Conventions

This document describes the Code Conventions used for Gridarta.

Code Conventions for the Java Programming Language

Additionally, the following set of rules applies:

Small Rules

("small" in the sense how long it takes to describe them, not in their importance!)

Field Initialization

Field initialization with the automatic default value is only allowed if the automatic default value carries semantics that are used later. In all other circumstances, which means in most cases, fields must not be initialized with the automatic default value. (The automatic default value is null, zero (any mutations of 0 or 0.0) or false.)

Stream I/O Handling

The following example code shows how streams should be opened / closed:

/*
 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
 * Copyright (C) 2000-2023 The Gridarta Developers.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class SafeCopy {

    public static void main(final String... args) throws IOException {
        try (InputStream in = new FileInputStream(args[0]);
             OutputStream out = new FileOutputStream(args[1])) {
            final byte[] buf = new byte[4096];
            while (true) {
                final int bytesRead = in.read(buf);
                if (bytesRead == -1) {
                    break;
                }
                out.write(buf, 0, bytesRead);
            }
        }
    }

}

Use try-with-resources. Rationale:

Checkstyle

The enforced rule set is Checkstyle: ./gradlew check runs Checkstyle 8.33 with config/checkstyle/checkstyle.xml on all Java sources, and the build fails on violations. Run it before submitting a patch. The main rules are:

The Rules in Detail

In addition to Checkstyle, the Gridarta developers use IntelliJ IDEA inspections. The inspection profile is not stored in the repository and is not run by the build. This description describes the inspection profile "No errors allowed here". As the name already suggests, this inspection profile must always run without errors. The purpose of this inspection profile is to prevent a regression of code quality. Currently it is quite small. New rules will be added whenever a certain level of cleanness and style is reached.

The following list explains the current rules, listed in a way that you can easily identify them in IntelliJ IDEA. It serves two purposes. One is to explain the rationale of the configured rules. The other is to enable developers that do not use IntelliJ IDEA / InspectionGadgets to know what the rules are to be able to perform the same verifications.

Gridarta SourceForge project page - Feedback: gridarta-devel mailing list
2026-10-23