You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bestpractices/c++practices.md
+20-22Lines changed: 20 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -613,30 +613,28 @@ When in doubt, use a struct - it is better to have good names than not.
613
613
614
614
## API Documentation
615
615
616
-
API Documentation in FreeCAD roughly consists of two types of API documentation. **Topics** that explain the concepts behind the code and **API documentation strings**. Both are important but topics are even more valued.
616
+
API Documentation in FreeCAD consists of two main types of documentation. **Topics** explain the concepts behind the code and **API documentation strings** explain the code itself. Both are important but topics are especially valued.
617
617
618
-
Although it is not required, it is encouraged to write API documentation when applicable. Note that it **is required** to make current API documentation up-to-date with changes that are made to the code. In this section we offer a set of guidelines.
618
+
Although it is not strictly required, developers are highly encouraged to write API documentation when applicable. Note that it **is required** to make current API documentation up-to-date with changes that are made to the code. This section presents a set of guidelines for that documentation.
619
619
620
620
### General guidelines
621
621
622
-
For the API documentation, the following general guidelines are recommended:
623
-
624
-
- Try to be as complete as possible with each item (classes, enums, public and protected members) in a file having a documentation string.
625
-
- Try to minimize the vertical space. So, when possible, use a single line with `///` or `///<` for enum items (see below).
622
+
- Be as complete as possible with each item (classes, enums, public and protected members) in a file having a documentation string.
623
+
- Minimize the vertical space. So, when possible, use a single line with `///` or `///<` for enum items (see below).
626
624
- In general, do not document C++ concepts such as destructors, friends, or constructors, except when there are arguments or if something special happens.
627
625
628
626
### Syntax
629
627
630
-
Doxygen supports two different types of syntax for commandswith a backslash and with an `@` symbol, for example `\brief` and `@brief`. The latter is more prevalent in the FreeCAD source code and preferred.
628
+
Doxygen supports two different types of syntax for commands, those with a backslash (e.g. `\brief`) and those with an `@` symbol (`@brief`). The `@`-prefixed version is more prevalent in the FreeCAD source code and is the preferred style for new documentation.
631
629
632
-
For a single line, for example commenting a function, we use `/// <your comment.` ending with a full stop without using `@brief`. Example:
630
+
For a single line API documentation comment, for example commenting a function, use `/// <your comment.` without using `@brief` and ending with a full stop. Example:
633
631
634
632
```c++
635
633
/// Get the transaction ID of this transaction.
636
634
int getID() const;
637
635
```
638
636
639
-
For multiple lines, we use `/**` to start the docstring. The documentation starts on the next line with a `@brief` command that ends with a full stop and then a line break. In the case below, there are details after which the `@param[in]` and `@return` commands document the parameters and return statement respectively.
637
+
For multiple lines, use `/**` to start the docstring. The documentation starts on the next line with a `@brief` command that ends with a full stop and then a line break. In the case below, there are details after which the `@param[in]` and `@return` commands document the parameters and return statement, respectively.
640
638
641
639
```c++
642
640
/**
@@ -651,7 +649,7 @@ For multiple lines, we use `/**` to start the docstring. The documentation star
651
649
static bool isValidName(const char* name);
652
650
```
653
651
654
-
If possible, it is advised to keep the number of added lines as low as possible. For example, you can use `///<` to keep the comments on the same line, for example in this Enum documentation:
652
+
Keep the number of added lines to a minimum. For example, use `///<` to keep the comments on the same line:
655
653
656
654
```c++
657
655
/// The status of the transaction object.
@@ -663,7 +661,7 @@ If possible, it is advised to keep the number of added lines as low as possible.
663
661
} status {New};
664
662
```
665
663
666
-
Use a single line to separate documentation of functions to make more clear to which function the documentation string belongs:
664
+
Use a single line to separate the documentation of different functions to make clearer to which function the documentation string belongs:
667
665
668
666
```c++
669
667
/// Generate a new unique transaction ID.
@@ -673,7 +671,7 @@ Use a single line to separate documentation of functions to make more clear to w
673
671
static int getLastID();
674
672
```
675
673
676
-
To prevent doxygen to automatically create a link you can use the `%` prefix. For example, since we have a namespace `Base` in FreeCAD, we use `%Base` in the example below to prevent Doxygen to create a link here to the `Base` package:
674
+
To prevent Doxygen from automatically creating an irrelevant or undesired link use a `%` prefix. For example, since there is a namespace `Base` in FreeCAD, use `%Base` as shown in the example below to prevent Doxygen to create a link here to the `Base` package:
677
675
678
676
```c++
679
677
/**
@@ -685,7 +683,7 @@ To prevent doxygen to automatically create a link you can use the `%` prefix. F
685
683
*/
686
684
```
687
685
688
-
It is possible to use Markdown syntax in doc comments. In the example below, we make use of a Markdown list:
686
+
It is possible to use Markdown syntax in doc comments. For example, a Markdown list:
689
687
690
688
```c++
691
689
/**
@@ -705,7 +703,7 @@ It is possible to use Markdown syntax in doc comments. In the example below, we
705
703
706
704
### Placing API documentation
707
705
708
-
The main page of the API documentation is in `src/Doc/mainpage.dox.in`. The most important function of this page is arguably the "Organization of the API Documentation" section that allows you to quickly browse important topics.
706
+
The main page of the API documentation is in `src/Doc/mainpage.dox.in`. The most important function of this page is the "Organization of the API Documentation" section allowing readers to quickly browse important topics.
709
707
710
708
Topics should be defined in dedicated `.dox` files in the main directory of a package. For example, `src/App/core-app.dox` defines a group `APP` that is in group `CORE` (defined in the main page) and then it defines several topics in `APP`, such as `DocumentGroup` (for the concept of a Document in FreeCAD), `DocumentObjectGroup` (for the concept of a document object), etc. Below are two excerpts from that file to give an indication:
711
709
@@ -758,15 +756,15 @@ class AppExport Document: public PropertyContainer
758
756
...
759
757
```
760
758
761
-
Documentation strings can be added to classes, enums, and public and protected members of a class. This is highly valued if a class is at the top of a hierarchy and its methods are reused in many other subclasses. The documentation should be added in the header file and not in the C++ file.
759
+
Documentation strings can be added to classes, enums, and public and protected members of a class. This is especially important if a class is at the top of a hierarchy and its methods are reused in many other subclasses. The documentation should be added in the header file and not in the C++ file.
762
760
763
761
### Specific guidelines
764
762
765
763
This section contains guidelines for specific types of documentation.
766
764
767
765
#### Namespaces
768
766
769
-
Since namespace statements are typically in many files, it is difficult to determine where to put documentation strings. The recommendation is to add them to the `.dox` file of the respective package. For example, in `src/App/core-app.dox` we have:
767
+
Since namespace statements are typically in many files, it is difficult to determine where to put documentation strings. In most cases a best practice is to add them to the `.dox` file of the respective module. For example, in `src/App/core-app.dox`:
770
768
771
769
```c++
772
770
/**
@@ -787,7 +785,7 @@ Since namespace statements are typically in many files, it is difficult to deter
787
785
788
786
#### Classes
789
787
790
-
For classes you can use a brief statement and more detailed comments:
788
+
For classes use a brief statement and more detailed comments:
791
789
792
790
```c++
793
791
/**
@@ -806,7 +804,7 @@ class AppExport Document: public PropertyContainer
806
804
807
805
#### Functions
808
806
809
-
For functions, you can use a brief statement, optionally more detailed comments and if applicable and the parameters are not trivial, `@param` statements marking the direction `[in]`, `[out]`, or `[in,out]`, a `@return` command and `@throws` command if applicable. An example:
807
+
For functions, use a brief statement, optionally more detailed comments, and if applicable and the parameters are not trivial, `@param` statements marking the direction `[in]`, `[out]`, or `[in,out]`, a `@return` command and `@throws` command, if applicable. An example:
810
808
811
809
```c++
812
810
/**
@@ -839,9 +837,9 @@ For enumerations, it often suffices to have a brief statement and a short commen
839
837
840
838
#### Grouping
841
839
842
-
Preferred is that a group starts with a documentation block `/**` with an `@name` command and an `@{` grouping command on the next line. The group is ended with `/// @}`.
840
+
Special documentation comments can be used to indicate that some group of functions, variables, etc. are all part of some single conceptual grouping. A best practice is to start a group with a documentation block `/**` with an `@name` command and an `@{` grouping command on the next line. The group is ended with `/// @}`.
843
841
844
-
Often, FreeCAD source files contain grouping commands with normal comments instead of documentation comments, such as `// @{` and `// @}`. Since these comments are not documentation comments, this usage is incorrect and can lead to issues in rendering the documentation.
842
+
Often, FreeCAD source files contain grouping commands with normal comments instead of documentation comments, such as `// @{` and `// @}`. Since these comments are not documentation comments, this usage is incorrect and can lead to issues in rendering the documentation. This usage should be avoided in new code, and corrected when encountered.
845
843
846
844
847
845
```c++
@@ -880,7 +878,7 @@ Templates can be document with a `@tparam` command:
880
878
881
879
#### Documentation with much repetition
882
880
883
-
The preferred way to handle code with much repetition is to use `@copydoc` or `@copydetails`.
881
+
The preferred way to handle code with significant repetition is to use `@copydoc` or `@copydetails`.
884
882
885
883
```c++
886
884
/**
@@ -951,7 +949,7 @@ An example with `@copydetails`:
Another way to handle documentation with a high degree of repetition is by grouping, although it is less preferred than using `@copydoc` or `@copydetails`.
952
+
Another way to handle documentation with a high degree of repetition is by grouping, although in most cases it is a best practice to use `@copydoc` or `@copydetails` instead.
0 commit comments