AgentSkillsCN

documenting-code-comments

倡导自文档化代码与精简注释的标准。当您需要审核内联文档,或判断何时注释能真正增值、何时反而会增加冗余时,可使用此技能。

SKILL.md
--- frontmatter
name: documenting-code-comments
description: Standards for self-documenting code and minimal comments. Use when auditing inline documentation or deciding when comments add value vs clutter.

Code Comments

Core principle: The best comment is the one you didn't need to write.

Hierarchy

  1. Make code self-documenting (naming, structure)
  2. Use type systems for contracts
  3. Add comments only for WHY, never WHAT

When NOT to Comment

AvoidWhy
// Get the user's nameRestates code
@param {string} emailTypes already document
Stale commentsMisleading > missing

When TO Comment

WHY, Not WHAT

typescript
// Use exponential backoff - service rate-limits after 3 rapid failures
const backoffMs = Math.pow(2, attempts) * 1000;

Gotchas and Edge Cases

typescript
// IMPORTANT: Assumes UTC - local timezone causes date drift
const dayStart = new Date(date.setHours(0, 0, 0, 0));

External Context

typescript
// Workaround for Safari flexbox bug (JIRA-1234)
// Per RFC 7231 §6.5.4, return 404 for missing resources

Performance Decisions

typescript
// Map for O(1) lookup - benchmarked 3x faster than array.find() at n>100
const userMap = new Map(users.map(u => [u.id, u]));

Refactor Before Commenting

Instead of commentRefactor to
// Get active usersconst activeUsers = users.filter(u => u.isActive)
// 86400000 ms = 1 dayconst ONE_DAY_MS = 24 * 60 * 60 * 1000
// Handle error caseExtract to handleAuthError(err)

TODO Format

typescript
// ✅ TODO(JIRA-567): Replace with batch API when available Q1 2025
// ❌ TODO: fix this later

Audit Checklist

  1. Necessity - Can code be refactored to eliminate comment?
  2. Accuracy - Does comment match current behavior?
  3. Value - Does it explain WHY, not WHAT?
  4. Actionability - TODOs have ticket references?