Comment Standards¶
This document defines the code comment standards for the DAWidgets project, ensuring consistency and completeness between documentation and code.
Language Requirement¶
Chinese Comments
The DAWidgets project uses Chinese for source code comments and Doxygen documentation comments.
This differs from the English-comment strategy used by internationally-oriented projects such as Qwt — DAWidgets is primarily targeted at the Chinese developer community. The rationale:
- The project's primary audience and maintainer community are Chinese-speaking developers.
- Comments explain why decisions were made, and expressing the reasoning in the maintainer's native language reduces ambiguity and improves review quality.
- The English documentation (in
docs/en/) is a translation layer for API consumers; the in-source comments remain Chinese so that the original intent is preserved without loss during translation.
Practical implication for contributors: When writing or modifying code, write all inline comments, Doxygen blocks, and class documentation in Chinese. Do not translate existing Chinese comments to English unless explicitly asked.
Core Requirements¶
Features
- ✅ Doxygen Format: Use Doxygen standard format for comments
- ✅ Chinese Comments: Source code comments are written in Chinese
- ✅ Placement Rules: Detailed comments in
.cpp, concise comments in.h - ✅ Completeness: Classes, functions, and signals all require complete documentation comments
Doxygen Keyword Standard¶
Doxygen keywords use the @ prefix (@brief, @param, @return, @details):
1 2 3 4 5 | |
Comment Placement Principles¶
Core Principle
- Detailed comments go in
.cppfiles - Concise comments go in
.hfiles - Headers should stay clean, avoiding excessive comment content
Header File Comment Standards¶
In header files, public function declarations only carry single-line concise Chinese comments.
Concise Comment Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Note
Do not write detailed Doxygen comment blocks in header files. Detailed content should go in the corresponding .cpp file.
Class Comment Standards¶
Class Doxygen comments are placed in the header file, containing @brief, @details, and a usage example.
Class Comment Template¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
Class Comment Key Points¶
@brief: One sentence describing the class's purpose@details: Detailed description of the class's behavior, modes, and features- Usage example:
@code/```cppcode block - Component mapping: If applicable, note which Element UI component it corresponds to
Source File Comment Standards¶
Function Comment Template¶
1 2 3 4 5 6 7 8 9 10 11 12 | |
Parameter Direction Annotations¶
Parameter direction annotations are recommended but not mandatory. For pass-by-value and const reference parameters, the direction is obvious and [in] can be omitted.
Direction must be annotated in the following cases:
@param[out]— non-const reference/pointer used for output results@param[in,out]— non-const reference/pointer that is both read and written
1 2 3 4 5 6 | |
Signal Comment Standards¶
Qt signals are declared in header files and have no corresponding cpp definition, so signal comments must be written completely in the header file.
Signal Comment Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Comment Style Checklist¶
| Check Item | Location | Requirement |
|---|---|---|
| Class comment | Header .h |
Chinese Doxygen, includes usage example |
| Public function detailed comment | Source .cpp |
Chinese Doxygen |
| Public function concise comment | Header .h |
Single-line Chinese |
| Signal comment | Header .h |
Chinese Doxygen (complete) |
| Private/protected functions | Source .cpp |
Optional, Chinese recommended |
| Inline comments | Any location | Chinese, explain "why" |
Common Mistakes¶
❌ Wrong: Detailed comments in header file¶
1 2 3 4 5 6 7 8 9 10 | |
❌ Wrong: Comments that say "what" not "why"¶
1 2 | |
✅ Correct: Concise header + detailed cpp¶
Header DASelectComboBox.h:
1 2 3 4 5 6 | |
Source DASelectComboBox.cpp:
1 2 3 4 5 6 7 8 9 10 11 | |