@@ -46,8 +46,21 @@ Avoid:
46
46
Rationale: clear, explicit types help with readability and understanding. Avoid hiding simple types behind `auto `.
47
47
48
48
49
+
49
50
Commenting Style
50
51
================
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
+
51
64
Comment types and rules:
52
65
53
66
- Use `/* ... */ ` **only ** for Doxygen documentation comments.
@@ -61,17 +74,55 @@ Formatting rules for `//` comments:
61
74
- Use full sentences when appropriate.
62
75
- For multi-line comments, prefix each line with `// `.
63
76
64
- Examples (correct usage) :
77
+ Incorrect usage:
65
78
66
79
.. code-block :: cpp
67
80
68
- // Check if the node has already been visited
81
+ /* Check if visited */ // Block comments are not allowed here
69
82
if (visited[node_id]) {
70
83
return;
71
84
}
72
85
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
75
126
76
127
/**
77
128
* @brief Estimates the wirelength of a net using bounding box.
@@ -81,16 +132,15 @@ Examples (correct usage):
81
132
*/
82
133
float estimate_wirelength(ClusterNetId net_id);
83
134
84
- Incorrect usage:
85
-
135
+ Example:
86
136
.. code-block :: cpp
87
137
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 ;
91
141
}
92
142
93
- //Missing space
94
- //inconsistent formatting
95
143
96
- /* Non-Doxygen block comment */ // Not permitted
144
+
145
+
146
+
0 commit comments