writing-code-comments
Fungsinya
Skill ini memandu AI untuk menulis lebih sedikit komentar kode, tetapi lebih baik. Ditujukan untuk pengembang yang menginginkan komentar yang menjelaskan alasan yang tidak dapat dilihat pembaca dari kode itu sendiri.
Kapan dipakai
- โSaat Anda akan menambahkan komentar ke kode dalam bahasa pemrograman apa pun.
- โSaat Anda meninjau perubahan yang menambahkan atau mengedit komentar.
- โSaat komentar hanya mengulang kode atau menjelaskan versi lama, dan Anda ingin membersihkannya.
Link skill
https://github.com/PostHog/posthog/blob/master/.agents/skills/writing-code-comments/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
โApakah saya perlu menambahkan komentar di sini? Bantu saya hanya menyimpan komentar yang menjelaskan alasannya.โ
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Sebelum menulis komentar, skill menanyakan apa yang disampaikan komentar itu kepada pembaca yang tidak ada di kode. Jika jawabannya hanya pengulangan dari kode, komentar dihapus dan nama yang lebih jelas disarankan sebagai gantinya.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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 counterabovecounter += 1 - โ
// loop over usersabovefor user of users - โ
# return the resultabovereturn 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 migrationleft 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 buildwhen the durable fact is that the build is expensive - โ
# ci-backend runs ~28m, so 60m โ one red resultinstead of "sized past a full run of the slowest workflow" - โ
# no story currently opts into webkit snapshotswhere dropping "currently" states the same fact - โ
# ~20 minutes in June, past 25 by Julybecause 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 the300(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."""onget_user_by_id - โ
# type: stringon 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
Pertanyaan umum
Apakah skill ini melarang penulisan komentar?
Tidak. Skill mempertahankan komentar yang menjelaskan alasan, seperti batasan tersembunyi atau konversi satuan, dan menghapus sisanya.
Di mana riwayat perubahan sebaiknya ditulis?
Di pesan commit dan deskripsi pull request, tempat riwayat itu tetap terkait dengan perubahannya. Komentar tentang versi lama di sumber cepat menjadi usang.
Apakah berfungsi untuk semua bahasa pemrograman?
Ya. Aturan yang sama berlaku untuk bahasa seperti Python, TypeScript, Go, Rust, dan SQL.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 41k
- Peringkat
- #6819
- Lisensi
- โ
- Diperbarui
- 2/11/2026
Komentar
- โฆ
Skill lain dari repositori ini
depot-ci
41kMembantu agent Anda menyiapkan dan menjalankan alur kerja Depot CI, alternatif GitHub Actions, termasuk memigrasikan alur kerja yang ada dan membaca log eksekusi.
depot-container-builds
41kMembantu agent Anda membangun image Docker di builder jarak jauh Depot, termasuk image multi-platform, pengiriman ke registry, dan perbaikan kegagalan build.
depot-github-runners
41kMembantu agent Anda memindahkan job GitHub Actions ke runner yang dikelola Depot, memilih ukuran dan label runner, serta memecahkan masalah pengaturan runner.
editing-agents-md
41kMembantu agent Anda memutuskan apakah sebuah aturan layak masuk ke berkas AGENTS.md atau CLAUDE.md, dan menulisnya agar tetap dipatuhi tanpa membuat berkas membengkak.
Skill serupa
diffs
394kMemungkinkan agent Anda menghasilkan diff perubahan yang nyata dan dapat dibagikan sebagai tautan viewer atau file gambar, bukan ringkasan yang ditulis manual.
coding-agent
394kMembantu agent Anda menyerahkan pekerjaan pemrograman besar ke Codex, Claude Code, atau OpenCode di latar belakang, lalu memeriksa kemajuannya.
gh-issues
394kMembantu agent Anda menemukan issue GitHub, memilih yang dikerjakan, dan membuka pull request perbaikan, termasuk tindak lanjut komentar tinjauan.