Skip to content

Add Doxygen Comments section into the code style guide #5694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,74 @@ Comments and Doc Comments
* rationale: mixing ``/* */`` and ``//`` is convenient for block commenting out code which contains comments
* Descriptions of how the code works or notes within classes and functions should use ``//`` style comments

Doxygen Comments
~~~~~~~~~~~~~~~~

* While it is allowed to use ``/** */`` style comments for documentation, we prefer ``///`` style
comments for Doxygen.
Comment on lines +165 to +166
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this wording is confusing, because it implies that people only use one or the other, while they instead might want to use a combination of both:

/// Brief.
/**
 * Detailed.
 *
 * \param name the name
 * \return a value
 */

So this should be clarified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is implied to use one or another.
I clarified it by

  1. Providing an example when mixing styles is not good
  2. Adding notes with clarification right after rationale list
  • Note that using /** */ Doxygen comments is useful in cases when C++ header files could
    participate in compilation with a C compiler, for instance, in C++/C mixed packages,
    when exposed API is written to comply with the C standard.
  • Need to keep consistency and adhere to the one style of Doxygen comments at least in the scope of
    the one file, i.e. either use /// or /** */ style comments.


* rationale: ``///`` is more consistent with the rest of the C++ code.
* rationale: ``///`` is easier to type and read in most editors.
* rationale: The Doxygen comments with ``///`` is easier to read in the code itself, as it is
more compact versus ``/** */`` which takes up more space and requires more lines.
Comment on lines +168 to +171
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to what @jmachowinski said (#5694 (comment)), I think these are highly subjective, especially numbers 2 and 3. I personally do not agree with them; I think /** */ is easier to type and easier to parse visually.

I'm Just trying to bring another perspective. I prefer picking a single style over picking a particular style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my explanation in the #5694 (comment) about why it is not easy to type.

* Note that using ``/** */`` Doxygen comments is useful in cases when C++ header files could
participate in compilation with a C compiler, for instance, in C++/C mixed packages,
when exposed API is written to comply with the C standard.

* Need to keep consistency and adhere to the one style of Doxygen comments at least in the scope of
the one file, i.e. either use ``///`` or ``/** */`` style comments.

* `Special commands <https://www.doxygen.nl/manual/commands.html>`__ like ``\brief``, and ``@param``
are the core annotation tools of Doxygen.
Doxygen recognizes words that begin with either backslashes ``(\)`` or at symbols ``(@)`` as
special commands.
For example, ``\param`` and ``@param`` are synonyms.
It is allowed to use both of them, but please keep consistency of usage at least in the scope
of one file.
Note: backslashes ``(\)`` are more C++ like style, while at symbols ``(@)`` are more Java/C style.

* Always use ``\brief`` or ``@brief`` explicitly before the brief description, and ``\details`` or
``@details`` explicitly before the detailed description of a function or class.
Start the explanation with upper case and end the line with a dot.

* rationale: This is the standard way to document functions and classes in Doxygen.
* rationale: To avoid misinterpreting of the sections by the documentation generation tools like
Doxygen and Sphinx.
* rationale: It makes it easier to read the documentation and understand the structure of the
comments.

* Use ``\param[in]`` or ``@param[in]`` to describe input parameters of a function, ``\param[out]``
or ``@param[out]`` for output parameters, and ``\param[in,out]`` or ``@param[in,out]`` for
parameters that are both input and output.

* Use ``\return`` or ``@return`` to describe the return value of a function, ``\note`` or
``@note`` to add a note, ``\warning`` or ``@warning`` to add a warning and ``\throws`` or
``@throws`` to describe exceptions that can be thrown by a function.

Example:

This is OK:

.. code-block:: c++

/// \brief Brief description of the function.
/// \details Detailed description of the function.
/// \param[in] param1 Description of the first parameter.
/// \param[out] param2 Description of the second parameter.
void my_function(int param1, int &param2);

This is **not** OK:

.. code-block:: c++

/// Brief description of the function
/**
* Detailed description of the function.
* \param param1 Description of the first parameter.
* \param param2 Description of the second parameter.
*/
Comment on lines +223 to +227
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* Detailed description of the function.
* \param param1 Description of the first parameter.
* \param param2 Description of the second parameter.
*/
/**
* Detailed description of the function.
* \param param1 Description of the first parameter.
* \param param2 Description of the second parameter.
*/

Basically all IDEs take care of this automatically.

Copy link
Contributor Author

@MichaelOrlov MichaelOrlov Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As regards

Basically all IDEs take care of this automatically.

Actually not. At least I would say most IDEs are partially taking care of those prefixes automatically.
Most IDEs add a prefixing space before the * marker when the user presses the Enter key.
However, when one tries to copy-paste such a block very often, that extra padding goes away.
And this is precisely what happened here! Believe me or not, it wasn't on purpose in this PR.
This is one of the major reasons why I am advocating for the C++ /// style.

cc: @jmachowinski @tfoote

void my_function(int param1, int &param2);

Pointer Syntax Alignment
~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down