Coding Conventions

Overview

The following coding conventions should be followed when submitting code to the project.
Anything not mentioned here should follow Sun's Java Conventions.

Conventions
  • Put the Session Tester header at the top of each new source file.
    SomeClass.java
    /*
     * Session Tester - The Exploratory Testing Tool, a tool to help manage
     * exploratory testing sessions, prime testing ideas and record test results.
     *
     * Copyright (C) 2010 Jonathan Kohl, Aaron West
     *
     * 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 3 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, see <http://www.gnu.org/licenses/>.
     */
    
    package somepackage;
    
    public class SomeClass
    {
        // code
    }
    
  • Place curly braces on new lines. Braces should be used even for one-line statements.
    Curly Braces
    if(expr)
    {
        // statement(s)
    }
    
    try
    {
        // statement(s)
    }
    catch(Exception e)
    {
        // statement(s)
    }
    finally
    {
        // statement(s)
    }
    
    for(;;)
    {
        // statement(s)
    }
    
  • Use four space indents. No tabs.
  • Use JavaDoc comments to document classes, methods, and other class members.
    JavaDoc Comments
    /**
     * A DeLorean-based, one-way, {@code TimeMachine} implementation that uses
     * four wheels to build up the speed necessary for wormhole traversal.
     */
    public class DeLorean implements TimeMachine
    {
        /**
         * Creates a new DeLorean ready for a one-way trip to
         * the specified destination.
         *
         * @param destination <i>when</i> to go.
         */
        public DeLorean(Date destination)
        {
            this.destination = destination;
            this.capacitor = new FluxCapacitor();
        }
    
        // ...
    
        private Date destination;
        private Capacitor capacitor;
    }
    
  • Use TODO to tag areas that require attention.
    Use TODO
    public class SomeList<E> implements List<E>
    {
        // ...
    
        /**
         * {@inheritDoc}
         */
        @Override
        public boolean add(E e)
        {
            // TODO: We should probably support this operation in 2.0.
            throw new UnsupportedOperationException();
        }
    
        // ...
    }
    
  • Use a maximum of 80 characters per line.
  • Import statements should be fully qualified. No star imports.
    Imports
    // Good.
    import java.util.List;
    import sessiontester.Persistor;
    
    // Evil.
    import java.util.*;
    
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Apr 08, 2010

    Louise Geijer says:

    Nice! I agree 100%. We should do this at work as well.. :)

    Nice! I agree 100%. We should do this at work as well.. :)