Skip to content

Commit cbe9a2a

Browse files
add Logging and Error Reporting section
1 parent 6098fb4 commit cbe9a2a

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

doc/src/dev/coding_style.rst

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,16 @@ Avoid Unnecessary Complexity
232232
auto&& get_ids() const && noexcept;
233233
234234
235-
- **Write short functions.** Functions should do one thing. Short functions are easier to understand, test, and reuse,
236-
and their purpose can be clearly described in a concise comment or documentation block.
237-
- **Limit function length.** If a function is growing too long or is difficult to describe in a sentence or two,
238-
consider splitting it into smaller helper functions.
239-
- **Favor simplicity.** Avoid clever or unnecessarily complex constructs. Code should be easy to read and maintain by others,
240-
not just the original author.
235+
- **Write short functions.** Functions should do one thing. Short functions are easier to understand, test, and reuse, and their purpose can be clearly described in a concise comment or documentation block.
236+
- **Limit function length.** If a function is growing too long or is difficult to describe in a sentence or two, consider splitting it into smaller helper functions.
237+
- **Favor simplicity.** Avoid clever or unnecessarily complex constructs. Code should be easy to read and maintain by others, not just the original author.
238+
- **Avoid deep abstract class hierarchies.** Excessive layering of virtual base classes makes the code hard to navigate and understand. Many tools (e.g., IDEs, LSPs) struggle to follow virtual call chains, especially in large or templated codebases.
239+
- **Avoid mixing templates with virtual functions.** This combination is particularly difficult to reason about and navigate. If you need to write generic code, prefer using either virtual dispatch or templates, but not both in the same interface.
241240
- Before adding new functions, classes, or utilities, check the codebase and documentation to see if a similar utility already exists.
242241
- Reuse or extend existing routines instead of duplicating functionality. This reduces bugs and makes the codebase more maintainable.
243242

244243

244+
245245
Group Related Data
246246
~~~~~~~~~~~~~~~~~~
247247

@@ -302,6 +302,30 @@ General Guidelines
302302
For more on assertion macros and their behavior, see :ref:`vtr_assertion` for more details.
303303

304304

305+
Logging and Error Reporting
306+
~~~~~~~~~~~~~
307+
Use the VTR logging and error handling utilities instead of raw `printf`, `std::cerr`, `exit()`, or `throw`.
308+
309+
- Use `VTR_LOG`, `VTR_LOG_WARN`, and `VTR_LOG_ERROR`
310+
311+
312+
.. code-block:: cpp
313+
314+
VTR_LOG("Incr Slack updates %zu in %g sec\n", incr_slack_updates, incr_slack_update_time_sec);
315+
316+
if (check_route_option == e_check_route_option::OFF) {
317+
VTR_LOG_WARN("The user disabled the check route step.");
318+
return;
319+
}
320+
321+
if (total_edges_to_node[inode] != 0) {
322+
VTR_LOG_ERROR("in check_rr_graph: SOURCE node %d has a fanin of %d, expected 0.\n", inode, total_edges_to_node[inode]);
323+
}
324+
325+
326+
Refer to :doc:`Logging - Errors - Assertions</api/vtrutil/logging>` to learn more about logging and error reporting.
327+
328+
305329

306330
Use of `auto`
307331
~~~~~~~~~~~~~

0 commit comments

Comments
 (0)