effective-commenting-strategies

在编写、审查或维护代码注释时使用的技能。应用策略以确保注释解释代码意图而非重复实现,采用便于维护的注释风格,并遵循注释密度规范。本技能覆盖注释类型、风格最佳实践以及与性能相关的考量。

仓库最近推送
GitHub Stars
140
Forks
36
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "effective-commenting-strategies":https://skillpi.com/zh/skills/deepskill-a301f0b1838ce86349f9e205cf3fb60b2683e0d3d5291634da4e366566b567ce。安装前核对上游来源和版本:https://github.com/kitchen-engineer42/pdf2skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

在编写、审查或维护代码注释时使用的技能。应用策略以确保注释解释代码意图而非重复实现,采用便于维护的注释风格,并遵循注释密度规范。本技能覆盖注释类型、风格最佳实践以及与性能相关的考量。

0 下载

介绍来源: third_party · kitchen-engineer42 · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
适合谁
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: effective-commenting-strategies
description: Use this skill when writing, reviewing, or maintaining code comments. Apply these strategies to ensure comments explain intent rather than repeat code, use maintainable styles, and follow density guidelines. This skill covers comment types, style best practices, and performance considerations.

Effective Commenting Strategies

Good comments explain the "why" behind code, not the "what." Use these strategies to write comments that enhance code maintainability without creating maintenance burden.

When to Use

  • Adding comments to new code
  • Reviewing existing comments for quality
  • Establishing team commenting standards
  • Optimizing comment density for readability
  • Handling performance-sensitive code with comments

Core Principle: Intent Over Repetition

Good comments should:

  • Not repeat code or explain what the code does
  • Clarify intent at a higher abstraction level than the code
  • Act as navigation like book headings or table of contents
  • Help maintenance by explaining the original programmer's intent
  • **Be efficient"—reading one English comment is faster than parsing 20 lines of code

Rule: If the code already explains everything, a comment that repeats it provides no value.

Comment Types

Marker Comments

Purpose: Remind developers of incomplete work (not intended for production)

Requirements:

  • Use standardized markers (e.g., ***, TBD, TODO)
  • Make markers mechanically searchable
  • Include in release checklist to prevent shipping known defects

Action: Search for all markers before release to ensure no incomplete code ships.

Explanatory Comments

Purpose: Explain complex, tricky, or sensitive code

Strategy:

  • If code is complex enough to need explanation, refactor the code first
  • Make the code itself clearer
  • Then use summary or intent comments if still needed

Summary Comments

Purpose: Condense several lines of code into one or two sentences

Value: More valuable than code-repeating comments because readers can scan them faster than reading code

When to use: Particularly helpful when non-original authors need to modify code

Intent Comments

Purpose: Explain the purpose of a code section at the intent/problem level

Level: Operates more at the problem level than the solution level

Example:

  • Intent: "Get current employee information"
  • Solution/Summary: "Update employeeRecord object"

Metadata Comments

Purpose: Record information that cannot be expressed in code

Includes:

  • Copyright notices
  • Confidentiality statements
  • Version numbers
  • Design notes
  • Requirement references
  • Online reference pointers
  • Optimization notes
  • Tool-required comments (e.g., Javadoc)

Maintainable Comment Style

Avoid High-Maintenance Styles

Do not use styles that require manual alignment:

  • ❌ Leader dots (...) connecting variables and descriptions
  • ❌ Asterisk boxes (*) surrounding paragraphs—requires adjusting both sides
  • ❌ Plus-sign underlines (+---+)—requires precise positioning when text length changes

Principle: Prefer accurate comments over pretty comments. If maintaining aesthetics requires tedious work, abandon that style.

Syntax Guidelines

For Java and C++:

  • Single-line comments: Use // syntax, keep comments short
  • Multi-line comments: Use /* ... */ syntax—easier to maintain than manually wrapped // lines

For emphasis: Use standard-length lines (via editor macros), not lines that vary with comment length

Comment Density Guidelines

Optimal Density

IBM Research Finding: Approximately 1 comment per 10 statements maximizes code clarity

  • Below this density: Code becomes difficult to understand
  • Above this density: Readability decreases

Avoid Quotas

Do not enforce rigid standards like "at least 1 comment per 5 lines"

Reason: This addresses the symptom (lack of comments) without solving the root cause (unclear code)

Performance Considerations

Principle: Do not avoid comments due to performance concerns (e.g., interpreted environments, network transmission overhead)

Solution: Create a separate release build

Implementation: Run a tool during the build process to automatically strip comments from the production version

Pseudocode Programming Process (PPP) Comment Efficiency

When using the Pseudocode Programming Process:

  1. Recognize the pattern: Effective PPP naturally results in "a comment every few lines"
  2. Understand the nature: Comment quantity is a side effect of the process, not a goal
  3. Focus on efficiency: Don't count comments—evaluate whether each comment is effective
  4. Assess sufficiency: Comments are sufficient if they:
    • Describe why the code was written
    • Meet the other standards in this skill

Conclusion: If comments explain "why" and meet quality standards, the quantity is adequate—don't worry about the number.

当前收录版本

0.0.1

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值78/100

亮点

  • 提供代码注释的实用策略,帮助开发者编写高质量注释
  • 涵盖注释类型、风格最佳实践和密度规范,内容全面
  • 适用于开发人员编写、审查和维护代码注释的广泛场景
触发精准92/100

亮点

  • 触发描述清晰明确,覆盖编写、审查、维护代码注释等多种场景
  • 边界清晰,不易与其他 Skill 重叠
结构规范95/100

亮点

  • 结构清晰,包含 When to Use、核心原则、注释类型、风格指南等完整章节
  • 提供了具体示例和 actionable 建议
  • frontmatter 完整,文档组织良好
执行可靠85/100

亮点

  • 提供可操作的策略和最佳实践,逻辑完整
  • 内容基于研究和实践经验,具有可靠性
证据可验 (前四项均值)88/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。