Skip to content

Commit 3f9cc2e

Browse files
update the section on commenting style
1 parent 1f3e43e commit 3f9cc2e

File tree

1 file changed

+62
-12
lines changed

1 file changed

+62
-12
lines changed

doc/src/dev/coding_style.rst

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,21 @@ Avoid:
4646
Rationale: clear, explicit types help with readability and understanding. Avoid hiding simple types behind `auto`.
4747

4848

49+
4950
Commenting Style
5051
================
52+
53+
Comments help readers understand the purpose, structure, and reasoning behind the code.
54+
This section outlines when and how to use comments in a consistent and helpful way.
55+
56+
General Rules
57+
-------------
58+
59+
- Focus on explaining *why* the code exists or behaves in a certain way.
60+
- Do not explain *what* the code is doing if it's already clear from the code itself.
61+
- Keep comments up to date. Outdated comments are worse than no comments.
62+
- Use Doxygen-style `/** ... */` or `///` for documenting APIs, classes, structs, members, and files.
63+
5164
Comment types and rules:
5265

5366
- Use `/* ... */` **only** for Doxygen documentation comments.
@@ -61,17 +74,55 @@ Formatting rules for `//` comments:
6174
- Use full sentences when appropriate.
6275
- For multi-line comments, prefix each line with `// `.
6376

64-
Examples (correct usage):
77+
Incorrect usage:
6578

6679
.. code-block:: cpp
6780
68-
// Check if the node has already been visited
81+
/* Check if visited */ // Block comments are not allowed here
6982
if (visited[node_id]) {
7083
return;
7184
}
7285
73-
// Enable debug output for route estimation
74-
bool debug_enabled = true;
86+
//Missing space
87+
//inconsistent formatting
88+
89+
/* Non-Doxygen block comment */ // Not permitted
90+
91+
When to Comment
92+
---------------
93+
94+
**1. File-Level Comments**
95+
- Every source/header file should begin with a brief comment explaining the overall purpose of the file.
96+
97+
**2. Classes and Structs**
98+
- Add a comment describing what the class or struct is for.
99+
- Comment every member variable to explain its role.
100+
101+
Example:
102+
.. code-block:: cpp
103+
104+
/**
105+
* @brief Manages TCP connections for a server.
106+
*/
107+
class ConnectionManager {
108+
public:
109+
/**
110+
* @brief Starts listening for incoming connections.
111+
*/
112+
void Start();
113+
114+
private:
115+
int port_; ///< Listening port.
116+
bool is_running_; ///< Whether the server is active.
117+
};
118+
119+
120+
**3. Functions**
121+
- All non-trivial functions must have a Doxygen comment in the header file or on the static declaration.
122+
- Explain what the function does, its parameters, and its return value.
123+
124+
Example:
125+
.. code-block:: cpp
75126
76127
/**
77128
* @brief Estimates the wirelength of a net using bounding box.
@@ -81,16 +132,15 @@ Examples (correct usage):
81132
*/
82133
float estimate_wirelength(ClusterNetId net_id);
83134
84-
Incorrect usage:
85-
135+
Example:
86136
.. code-block:: cpp
87137
88-
/* Check if visited */ // Block comments are not allowed here
89-
if (visited[node_id]) {
90-
return;
138+
// Skip ignored nets
139+
if (net.is_ignored()) {
140+
continue;
91141
}
92142
93-
//Missing space
94-
//inconsistent formatting
95143
96-
/* Non-Doxygen block comment */ // Not permitted
144+
145+
146+

0 commit comments

Comments
 (0)