Project

General

Profile

Writing Convention

Rules and style to write C++ programs

General

  • Use common sense and BE CONSISTENT.
    If you are editing code, take a few minutes to look at the code around you and determine its style. If they use spaces around their if clauses, you should, too. If their comments have little boxes of stars around them, make your comments have little boxes of stars around them too.
  • The #define Guard
    All header files should have #define guards to prevent multiple inclusion. The format of the symbol name should be _HEADERNAME_H.
  • Reference Arguments
    All parameters passed by reference must be labeled const.
  • sizeof
    Prefer sizeof(varname) to sizeof(type).
  • Exceptions
    Use C++ exceptions only to handle errors, not for alternative code flows execution.
  • Run-Time Type Information (RTTI)
    Avoid using Run Time Type Information (RTTI).
  • No Macros
    Use inline functions, enums, and const variables instead of macros.
  • C++11
    Use only approved libraries and language extensions from C++11 (formerly known as C++0x). Consider portability to other environments before using C++11 features in your project.

Comments

  • Application Comments
    Write a README.dox for each application to add comments in the doxygen docs mainpage.
   /** \mainpage Name of Program
   *
   *  \section Abstract
   *
   *  This program process raw data taking from Simulation Montecarlo ASTRI data and create a L0 FITS file.
   *
   *  \Library Required
   *  - Internal library:
   *    -# PacketLib;
   *    -# ProcessorLib;
   *
   *  - External library:
   *   -# heasoft CFITSIO.
   */

Formatting

  • Preprocessor Directives
    The hash mark that starts a preprocessor directive should always be at the beginning of the line.
  • Namespace Formatting
    The contents of namespaces are not indented.
  • Line Length
    Each line of text in your code should be at most 80 characters long.
  • Non-ASCII Characters
    Non-ASCII characters should be rare, and must use UTF-8 formatting.
  • Spaces vs. Tabs
    Use tabs if possible, but be consistent with the block of code.
  • Horizontal Whitespace
    Use of horizontal whitespace depends on location. Never put trailing whitespace at the end of a line.
  • Vertical Whitespace
    Minimize use of vertical whitespace.

Rules and style to write Python programs
*TBD*