coding-style
编写清晰、专业代码的指南。在编写或修改代码、创建提交或生成代码注释时使用。确保代码是为团队消费而编写的,没有对话痕迹。
name: coding-style description: Guidelines for writing clean, professional code. Use when writing or modifying code, creating commits, or generating code comments. Ensures code is written for team consumption without conversation artifacts.
Coding Style Guidelines
Context-Free Communication
Never reference our conversation in code, commits, or comments. Avoid phrases like:
- "Option A/B"
- "as discussed"
- "per your request"
- "as mentioned earlier"
Write for developers who will read the code without access to this chat.
Comments
Avoid tutorial-style or learning-oriented comments such as:
// someFunctionName is no longer needed here// We removed this because...- Explanatory comments directed at the developer making the change
Only add comments that explain non-obvious "why" decisions that future maintainers need to understand.
Write for the Team
Commits, comments, and code will be read by other developers. Explain the "why" in a way that stands alone. The code and its history should be self-documenting without requiring conversation context.
Newspaper Article Code Organization
Structure code with important elements at the top, details below—like a newspaper article where the headline comes first.
Ordering principles:
- Public members before private members
- Public functions before private functions
- High-level logic before implementation details
- When extracting a helper function from a larger function, place the helper after the original function
This allows readers to understand the public API and main flow before diving into implementation details.