The original FLTK coding standards are in blue.
erco's comments are in red.
matthias' comments are in green
duncan's comments in purple
albrecht's comments in orange
Add your own name/color here (cyan, magenta..)

WARNING: I've noticed some kind of bug in google's text editor that sometimes drops or modifies
whitespace indenting. Hard to replicate, but I can indent something with spaces, save, return and indent is wrong.
Must be what the 'BETA' is for in 'Google Docs BETA'.. :/
---------------------------------------------------------


Documentation (Comments)

FLTK 2.0 and FLTK 1.3 and up use Doxygen with the JavaDoc comment style to document all classes, structures, enumerations, methods, and functions. Doxygen comments are mandatory for all FLTK header and source files, and no FLTK release will be made without complete documentation of public APIs. Here is an example of the Doxygen comment style:


/**
  The Foo class implements the Foo widget for FLTK.

  This description text appears in the documentation for
  the class and may include HTML tags as desired.
*/
class FL_EXPORT Foo : public Widget {
  int private_data_;

  public:

  /**
    Creates a Foo widget with the given position and label.

    This description text appears in the documentation for the
    method's implementation.

    References to parameters \p X, \p Y, \p W, \p H are
    mentioned this way.

    \param[in] X,Y,W,H Position and size of widget
    \param[in] L Optional label (default is 0 for no label)
  */
  Foo(int X, int Y, int W, int H, const char *L = 0) {
    ..implementation here..
  }
};

I do like when (*)s run down left margin of all comments; easier to differentiate comments from code in large doc blocks. -Erco 3/14/09 11:26 AM
Yes, same here. I usually align them in the second column. -Matthias Melcher 3/14/09 11:02 PM 

Duncan doesn't like (*)s down the left because it complicates paragraph reformatting.. passing that on. -Erco 3/15/09 1:12 PM 

Albrecht says this was already discussed and decision was *no stars* down the left, so I modified the examples here. -Erco 3/15/09 2:30 PM

Note: fltk2 uses QT /*! style comments, whereas fltk1 uses /** as described above. Should standard reflect this? -Erco 3/15/09 2:36 PM


Essentially, a comment starting with /** before the class or method defines the documentation for that class or method. These comments should appear in the header file for classes and inline methods and in the code file for non-inline methods.

In addition to Doxygen comments, block comments must be used liberally in the code to describe what is being done. If what you are doing is not "intuitively obvious to a casual observer", add a comment! Remember, you're not the only one that has to read, maintain, and debug the code.


Never use C++ comments in C code files or in header files that may be included from a C program. Normally, fltk C files have ".c" and ".h" file extensions, and C++ have ".cxx" and ".H". Currently there are a few exceptions; filename.H and Fl_Exports.H both get interpreted by C and C++, so you must use C style comments in those. (Otherwise builds on strict platforms like SGI will fail).


General Developer Recommendations

Most of these notes are from Fabien's TODO.doc, and seem consistent with the actual fltk docs -Erco 3/14/09 11:03 AM
Most important rule: "Put Doxygen comments wherever the code implementation is"


         /** ... */ for standard comments

         ///< for single line post-declaration short comments


         /** ... */ for standard comments
         /**< ... */ for single line post-declaration short comments


Use \p for parameters citation in the description, \param[in] xxx and \param[out] xxx for input/output parameters.
Don't use doxygen tags between a \htmlonly \endhmltonly pair of tags.
When commenting out code, be sure not to accidentally use doxygen comment styles, or your commented out code will be published..! Beware doxygen recognizes other comment styles for itself:

    /*! beware */
    /*@ beware */
    //! beware
    //@ beware

There may be others. For this reason, it's best to follow all normal C/C++ style comments with a space, to avoid doxygen parsing, eg.

    /*<space> safe from doxygen */
    //<space> safe from doxygen
    etc.

I hope the above is true -- I'm surmising. -Erco 3/14/09 11:17 AM

Note that within doxygen comments, several characters are 'special' and have to be escaped with a backslash in order to appear in the docs correctly. Some of these codes are:


        \<    -- disambiguates html tags
        \>    -- ""
        \&    -- ""
        \@    -- disambiguates JavaDoc doxygen comments
        \$    -- disambiguates environment variable expansions
        \#    -- disambiguates references to documented entities
        \%    -- prevents auto-linking
        \\    -- escapes the escape character

For a complete list, see Chapter 23 of the doxygen docs.

Itemized lists can be specified two ways; both are OK, left is preferred:

/** Here's a bullet list:
  
      - Apples
      - Oranges
 
   Here's a numbered list:
  
      -# First thing
      -# Second thing
  
 */
/** Here's a bullet list:
    <ul>
        <li> Apples</li>
        <li> Oranges</li>
    </ul>
    Here's a numbered list:
    <ol>
        <li> First thing</li>
        <li> Second thing</li>
    <ol>
 *

Documenting Temporary Code or Issues

Temporary code and code that has a known issue MUST be documented in-line with the following (Doxygen) comment style:


/** \todo this code is temporary */


\todo items are listed by Doxygen making it easy to locate any code that has an outstanding issue or code that should be removed or commented out prior to a release.

Documenting Classes and Structures

Classes and structures start with a comment block that looks like the following:


/**
  A brief description of the class/structure.

  A complete description of the class/structure.
*/
class MyClass {
  ..
};

Documenting Enumerations

Enumerations start with a comment block that looks like the following:


/**
  A brief description of the enumeration.

  A complete description of the enumeration.
*/

enum MyEnum {
  ...
};

Each enumeration value must be documented in-line next to the corresponding definition as follows:


/* C STYLE */
enum MyEnum {
  BLACK,   /**< The color black. */
  RED,     /**< The color red. */
  GREEN,   /**< The color green. */
  YELLOW,  /**< The color yellow. */
  BLUE     /**< The color blue. */
};
/* C++ STYLE */
enum MyEnum {
  BLACK,   //< The color black.
  RED,     //< The color red.
  GREEN,   //< The color green.
  YELLOW,  //< The color yellow.
  BLUE     //< The color blue.
};

I prefer the right; avoids accidental unclosed comments + less to type -Erco 3/14/09 11:25 AM 

Documenting Functions and Methods

Functions and methods start with a comment block that looks like the following:


/**
  A brief description of the function/method.

  A complete description of the function/method.
Passing mention of arguments \p a and \p b.

  Optional code example:
  \code
  int w=0, h=0; // must be 0!
  fl_measure(s,w,h);
  \endcode

  \param[in] X,Y,W,H Description of all four variables at once
  \param[in] a What "a" input is.

  \param[in] b What "b" input is.
  \param[out] out1 What "out1" output is
  \param[out] out2 What "out2" output is
  \returns What this function/method returns.
  \see Related methods foo1(), foo2(), foo3()
*/
int my_function(int a, int b, float &out1, float &out2) {
  ...implementation...
}


Each parameter is documented using \param[in|out]. The return value is documenting using \return; omit the return value comment if the function/method does not return a value or is a constructor. Use \see to refer to other, related functions/methods. Passing mention of parameters in docs should use "\p varname". (Use \p instead of \a; \p shows in a different font face, making it clearer to see than \a in the index and in printouts)


Note doxygen will check your \param[in/out] xxx variable names, and will complain if they don't match the method's declaration variable names. This is a good thing, so definitely use it so we can see discrepancies between the code and the docs. Note that doxygen does NOT check \p names for consistency.


Function/method documentation must be placed next to the corresponding code. (Rule: "Put the docs where the code implementation is.") Comments for in-line functions and methods in header files are placed in the header file.


Use \code and \endcode when code examples are needed. Text within \code is exempt from html and doxygen escape code parsing, so you don't have to escape characters <, >, &, etc. as you would normally. Be careful not to embed C style comments within \code, as it will conflict with the doxygen comment block. 


Since methods are being sorted alphabetically by doxygen, like-kind methods should be 'grouped' together by using "\see Related methods xxx(), yyy().."; put this below the \param[]s and \returns (as shown above).

In the above, I changed all @param's to \param because that seems to be what's actually in the code. -Erco 3/14/09 10:59 AM 

Documenting Members and Variables

Members and variables can be documented in one of two ways; in block comment form as follows:


/**
  A brief description of the member/variable.

  A complete description of the member/variable.
*/
int my_variable_;


or in the preferred form as in-line comments as follows:


int my_variable_;    ///< A brief description of the member/variable in a C++ file
int my_variable_;    /**< A brief description of the member/variable in a C file. */

Editor Settings For Doxygen

Some editors support 'folding' or 'collapsing' doxygen comments, so one can see the code without the doxygen docs just by hitting a few keys. This avoids having to navigate over distracting user documentation during coding, making it easier to move through the document and see more code per page. For examples of this feature in vim, see:

  1. A video demo of doxygen folding in vim,
  2. A screenshot showing a side-by-side of vim with doxygen comments on vs. off.


Document History

2009-03-14: some formatting and testing by Matthias
2009-03-14: C vs. C++ doxygen practices and other additions by Greg
2009-03-14: import of original documentation into Google Docs
[--END--]