ADMB Coding Standards

Coding Standards improve readability and to help insure that code written by multiple authors has the same consistent appearance.

Below are guidelines and recommendations for writing and maintaining source code.

ADMB uses rules from:

General Principles

The most important principles are the first 2 from Misfeldt et al

ADMB Coding Standards

  1. All files should have CR line endings.

    Windows text files that are opened in unix show ^M characters which makes the file less readable.

    Note — Exceptions are the windows batch files.

  2. Avoid the use of tab character in source files.

    Tabs display differently in various editors.

  3. Use two (2) spaces for indents.

    This is common in most coding standards. See Indenting script below.

  4. Lines should be no longer than 80 characters.

    This makes it easier to print and display in command line shells.

  5. Avoid spaces at the end of lines.

  6. Place opening and closing braces on their own line and align them.

    For example.

    if (x < 0.0)
    {
      y = a;
    }
    else
    {
      y = b * x;
    }
    

    Indenting script

    Many linux-like systems have the indent utility. The following bash script produces nice-looking code, but it is not perfect, and some additional work with an editor may be required.

    #!/bin/bash
    #
    # reformats source code to ADMB style using indent
    # see http://www.gnu.org/software/indent/
    #
    # Author: John Sibert
    #
    cp -v $1 $1.bak
    indent -nbad -bap -bbo -nbc -bl -blf -bli0 -bls -c33\
     -cd33 -ncdb -ce -ci3 -cli0 -cp33 -cs -d0 -di1 -nfc1\
     -nfca -hnl -i3 -ip0 -l75 -lp -npcs -nprs -npsl -saf\
     -sai -saw -nsc -nsob -nss $1 -o indent.out
    cp -v indent.out $1
    
  7. Avoid mixing lower and uppercase characters in classes and functions. Do not use isCamelBack() notation.

Naming Conventions