MR
Mayur Rathi
@github
⭐ 34.1k GitHub stars

Self-Explanatory-Code-Commenting

Self-Explanatory-Code-Commenting是一款code方向的AI技能,核心价值是Guidelines for GitHub Copilot to write comments to achieve self-explanatory code with less comments,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。

Guidelines for GitHub Copilot to write comments to achieve self-explanatory code with less comments. Examples are in JavaScript but it should work on any language that has comments.

Last verified on: 2026-05-30
mkdir -p ./skills/self-explanatory-code-commenting && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/self-explanatory-code-commenting/SKILL.md -o ./skills/self-explanatory-code-commenting/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# Self-explanatory Code Commenting Instructions


Core Principle

**Write code that speaks for itself. Comment only when necessary to explain WHY, not WHAT.**

We do not need comments most of the time.


Commenting Guidelines


❌ AVOID These Comment Types


**Obvious Comments**

javascript
// Bad: States the obvious
let counter = 0;  // Initialize counter to zero
counter++;  // Increment counter by one

**Redundant Comments**

javascript
// Bad: Comment repeats the code
function getUserName() {
    return user.name;  // Return the user's name
}

**Outdated Comments**

javascript
// Bad: Comment doesn't match the code
// Calculate tax at 5% rate
const tax = price * 0.08;  // Actually 8%

✅ WRITE These Comment Types


**Complex Business Logic**

javascript
// Good: Explains WHY this specific calculation
// Apply progressive tax brackets: 10% up to 10k, 20% above
const tax = calculateProgressiveTax(income, [0.10, 0.20], [10000]);

**Non-obvious Algorithms**

javascript
// Good: Explains the algorithm choice
// Using Floyd-Warshall for all-pairs shortest paths
// because we need distances between all nodes
for (let k = 0; k < vertices; k++) {
    for (let i = 0; i < vertices; i++) {
        for (let j = 0; j < vertices; j++) {
            // ... implementation
        }
    }
}

**Regex Patterns**

javascript
// Good: Explains what the regex matches
// Match email format: username@domain.extension
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;

**API Constraints or Gotchas**

javascript
// Good: Explains external constraint
// GitHub API rate limit: 5000 requests/hour for authenticated users
await rateLimiter.wait();
const response = await fetch(githubApiUrl);

Decision Framework


Before writing a comment, ask:

1. **Is the code self-explanatory?** → No comment needed

2. **Would a better variable/function name eliminate the need?** → Refactor instead

3. **Does this explain WHY, not WHAT?** → Good comment

4. **Will this help future maintainers?** → Good comment


Special Cases for Comments


Public APIs

javascript
/**
 * Calculate compound interest using the standard formula.
 * 
 * @param {number} principal - Initial amount invested
 * @param {number} rate - Annual interest rate (as decimal, e.g., 0.05 for 5%)
 * @param {number} time - Time period in years
 * @param {number} compoundFrequency - How many times per year interest compounds (default: 1)
 * @returns {number} Final amount after compound interest
 */
function calculateCompoundInterest(principal, rate, time, compoundFrequency = 1) {
    // ... implementation
}

Configuration and Constants

javascript
// Good: Explains the source or reasoning
const MAX_RETRIES = 3;  // Based on network reliability studies
const API_TIMEOUT = 5000;  // AWS Lambda timeout is 15s, leaving buffer

Annotations

javascript
// TODO: Replace with proper user authentication after security review
// FIXME: Memory leak in production - investigate connection pooling
// HACK: Workaround for bug in library v2.1.0 - remove after upgrade
// NOTE: This implementation assumes UTC timezone for all calculations
// WARNING: This function modifies the original array instead of creating a copy
// PERF: Consider caching this result if called frequently in hot path
// SECURITY: Validate input to prevent SQL injection before using in query
// BUG: Edge case failure when array is empty - needs investigation
// REFACTOR: Extract this logic into separate utility function for reusability
// DEPRECATED: Use newApiFunction() instead - this will be removed in v3.0

Anti-Patterns to Avoid


Dead Code Comments

javascript
// Bad: Don't comment out code
// const oldFunction = () => { ... };
const newFunction = () => { ... };

Changelog Comments

javascript
// Bad: Don't maintain history in comments
// Modified by John on 2023-01-15
// Fixed bug reported by Sarah on 2023-02-03
function processData() {

🎯 Best For

  • UI designers
  • Product designers
  • Claude users
  • GitHub Copilot users
  • Software engineers

💡 Use Cases

  • Generating component mockups
  • Creating design system tokens
  • Code quality improvement
  • Best practice enforcement

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply Self-Explanatory-Code-Commenting to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Does this work with Figma?

Some design skills integrate with Figma plugins. Check the Works With section for supported tools.

Is Self-Explanatory-Code-Commenting compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for Self-Explanatory-Code-Commenting?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install Self-Explanatory-Code-Commenting?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/self-explanatory-code-commenting/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Skipping usability testing

AI-generated designs should be validated with real users before development.

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills