wiki:CodingStyle

ARB coding style

  • TABs are completely unwanted in ARB code, use spaces!
  • Indentation size is 4 spaces.
  • Preferred bracket style:
        if (cond) {
            while (!abort) {
               doSth();
            }
        }
        else {
            doOth();
        }
    
    As a rule of thumb: Use brackets on every block.
    Only skip them for one-liners like
        if (this) doThat();
    
  • If your editor automatically removes spaces at EOL, please disable that feature.
  • Compiler warnings have not been designed and enabled to be ignored ;-)

Naming conventions

  • Each function name should be globally unique, to support text-bases search (as grep or ctags). Each function - not only global functions!
  • The following conventions just reflect the historical conformity in existing code:
    • For database pointers we use gb_ plus description (e.g. GBDATA *gb_name = GB_search(gb_species, "name", GB_STRING);)
    • Globally visible types and functions start with an prefix in upper-case (like SEC_db_interface or DI_create_save_matrix_window). For each semantic "group of code" one unique prefix shall be used.

References

  • When referring between somehow coupled parts of the code (especially if coupling crosses module borders) use the following syntax
    • add a comment containing relPathName@UniqueID where
      • relPathName is the relative unix path from the commented file to the referred file
      • UniqueID is unique in referred file (should only contain alphanumeric characters)
    • such a comment defines a link which may be used for navigation.
    • PRE to grep for these references:
      \s[\w./]+\.[\w]+@[\w]+(\s.*|)$
      
  • Example: ST_quality.cxx <> EDB_root_bact.cxx
  • ARB code widely violates the DRY principle. When you detect such violation and cannot fix it instantly, at least document it using the above reference type.

Using indent

The following indent parameters may be used to format ARB code:

indent *.[ch]pp *.[ch]xx *.[ch] \ 
    --line-length 160 \
    --indent-level 4 \
    --no-tabs \
    \
    --no-blank-lines-after-declarations \ 
    --blank-lines-after-procedures \
    \
    --no-space-after-casts \
    --no-space-after-function-call-names \
    --space-special-semicolon \
    \
    --braces-on-if-line \
    --braces-on-struct-decl-line \
    --braces-on-func-def-line \
    --continue-at-parentheses \
    --cuddle-do-while \
    --case-indentation4 \
    --case-brace-indentation0 \
    --dont-break-function-decl-args \
    --dont-break-procedure-type \
    \
    --leave-preprocessor-space \

Using astyle

The following astyle parameters may be used to format ARB code:

astyle \
    --suffix=none \
    --indent=spaces=4 \
    --indent-switches \
    --convert-tabs \
    --brackets=attach \
    --break-closing-brackets \
    --keep-one-line-blocks \
    --keep-one-line-statements \
    --unpad-paren \
    --max-instatement-indent=200 \
    --min-conditional-indent=0 \
    *.[ch]xx

Notes:

  • indent is not capable to format one-line-if-statements in the way recommended above!
  • separate reformatting and real code changes when committing to repository
Last modified 13 years ago Last modified on Jun 4, 2012, 2:42:11 PM