본문으로 건너뛰기
Skillpedia
일반 코딩41k · #6819

writing-code-comments

하는 일

이 스킬은 AI가 주석을 더 적고 더 좋게 쓰도록 안내합니다. 코드 자체에서 읽는 사람이 볼 수 없는 이유를 설명하는 주석을 원하는 개발자를 위한 것입니다.

사용하는 경우

  • ✓어떤 프로그래밍 언어의 코드에든 주석을 추가하려고 할 때.
  • ✓주석을 추가하거나 수정하는 변경을 검토할 때.
  • ✓주석이 코드를 되풀이하거나 과거 버전을 설명할 때 정리하고 싶을 때.

스킬 링크

https://github.com/PostHog/posthog/blob/master/.agents/skills/writing-code-comments/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/PostHog/posthog/blob/master/.agents/skills/writing-code-comments/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“여기에 주석을 달아야 할까요? 이유를 설명하는 주석만 남기도록 도와주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

주석을 쓰기 전에, 이 주석이 코드에 없는 무엇을 알려 주는지 묻습니다. 답이 코드를 되풀이하는 것뿐이라면 주석을 지우고, 대신 더 명확한 이름을 제안합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Writing code comments

Run this before adding or editing any comment. The default is no comment. Good code with clear names carries most of its meaning on its own; a comment earns its place only when it tells a reader something the code cannot.

The gate: one question

Before writing a comment, answer:

What does this tell a future reader that the code itself doesn't?

If the answer is "it restates what the code does", delete it. Rename the variable or extract a function instead.

A comment worth keeping answers a why the code can't:

  • ✅ # ATOMIC_REQUESTS is off, so wrap the two writes that must commit together
  • ✅ // Stripe sends the amount in cents; the rest of our system uses dollars
  • ✅ # Kept in sync with the enum in migrations/0042; update both

Delete these

Narration that restates the code

  • ❌ # increment the counter above counter += 1
  • ❌ // loop over users above for user of users
  • ❌ # return the result above return result

If a block needs narration to be followed, the fix is smaller functions and better names, not a comment.

Change history and chat context

Never record how the code got here. That belongs in the commit message and PR description, where it's attached to the diff and searchable. In the source it's noise that goes stale immediately.

  • ❌ # previously used a set here, switched to a list for ordering
  • ❌ // per PR #1234 / # as discussed / # changed because the old way broke
  • ❌ # AI: generated this helper / // agent: refactored
  • ❌ # TODO(2024-01): remove after migration left in long after the migration

Perishable measurements and current-state stamps

Measured timings, counts, and rates rot silently: nothing forces them to update, and a rotted number misleads the next person sizing a timeout or shard count. The same goes for "currently" / "today" hedges, because the sentence states the same fact without them. State the durable relationship the number stood for.

  • ❌ # skip the ~20 min build when the durable fact is that the build is expensive
  • ❌ # ci-backend runs ~28m, so 60m ≈ one red result instead of "sized past a full run of the slowest workflow"
  • ❌ # no story currently opts into webkit snapshots where dropping "currently" states the same fact
  • ❌ # ~20 minutes in June, past 25 by July because trend narration is change history

Numbers that stay:

  • A dated snapshot: # as of August 2024, Homebrew ships 4.13.2 (the date makes staleness visible)
  • A restated adjacent code literal: # runs that took >5 min (300 seconds) beside the 300 (it updates with the code)
  • A platform constant: # GitHub's comment size limit (~64KB)
  • A target or budget: # Target: ~15 min per shard (policy, not measurement)
  • Cited evidence: # 30% peak memory observed on 16-core runs (#46853) (the link dates it)

Commented-out code

Delete it; the version history has it if it's needed again. Commented-out code is ambiguous to the next reader, who can't tell whether it's a note, a rollback plan, or an accident.

Redundant docstrings and type restatements

  • ❌ A docstring that repeats the function name in prose: """Gets the user by id.""" on get_user_by_id
  • ❌ # type: string on an already-typed field
  • ❌ Python test doc comments (the repo convention is none; the test name says it)

Keep these

  • A why that isn't obvious from the code: a workaround, a performance trade-off, a spec quirk, an ordering constraint.
  • A warning about a consequence that lives elsewhere: "changing this breaks the cache key", "callers rely on this being sorted".
  • A pointer to context a reader can't reconstruct from the repo: a link to the spec, ticket, or the reason a surprising value was chosen.

Style

Write comments the way you'd write technical documentation: explicit and precise. State the reasoning so the reader does not have to infer it. Length is not a target in either direction: don't clip a comment to look terse, and don't pad it to look thorough. Say what needs saying and stop.

  • Be explicit and technical. State the cause and effect. Name the actual conditions, values, and consequences. A reader should not have to reconstruct your reasoning from a hint.
  • Use mostly ASD-STE100 Simplified Technical English. Use active voice, simple tenses, one idea per sentence, and consistent terms.
  • Let length follow the content. One line is fine when one line covers it; use more when the reasoning needs more. Neither brev
자주 묻는 질문

스킬이 주석을 쓰지 말라고 하나요?

아니요. 숨겨진 제약이나 단위 변환처럼 이유를 설명하는 주석은 남기고, 나머지는 지웁니다.

변경 이력은 어디에 적어야 하나요?

커밋 메시지와 풀 리퀘스트 설명에 적어야 합니다. 변경과 함께 보관되기 때문입니다. 소스의 과거 버전에 대한 주석은 금방 낡습니다.

모든 프로그래밍 언어에서 작동하나요?

네. Python, TypeScript, Go, Rust, SQL 같은 언어에도 같은 규칙이 적용됩니다.

상세 정보

작성자의 원본 설명

Gates whether a code comment should exist and forces the ones that stay to explain why, not what. Use ALWAYS before writing or editing a comment in any language (Python, TypeScript, Go, Rust, SQL), and when reviewing a diff that adds comments. Removes the comment types that clutter the codebase: narration that restates the code, change-history and chat-context notes ("previously did X", "per PR #123", "AI:"), perishable measurements and current-state stamps ("~20 min build", "currently", "today"), commented-out code, and redundant docstrings. Keeps the ones that earn their place: a non-obvious

repo: PostHog/posthog

인기도

GitHub 스타
41k
순위
#6819
라이선스
—
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬