document-code
БесплатноБез исполняемых скриптовНе проверенDecide whether a comment belongs, and write the ones that do — in Ruby, YAML, a Dockerfile, a shell script, tests or config. Use it before adding any comment…
от hoblin★ 38 звёзд на GitHubОб этом скилле
A comment is judged only together with the block of code it comments, never on its own. Whether it is needed, what it should say, and whether it should be deleted are decided by reading the two side by side.
Documenting is its own pass
Documentation starts once the code works, and not before. A comment written mid-implementation is written by someone still deciding, so what it captures is the deciding rather than the decision. Write no comments during implementation at all, and the pass that follows has nothing to judge and only something to add.
What you are documenting
Step one: your first output names what you are about to document — Published interface or Implementation. Say it again whenever you move to code of the other kind.
A published interface is code that other people call without reading it: a gem, an engine, a package another team consumes. Its comments are rendered by YARD, RDoc, an IDE hover or ri, away from the source, so they have to stand alone. Application code — app/, a service's lib/ — has almost no published interface: whoever wants to know what a service does opens the service. The answer is not "is the repository public": an internal package another team consumes without reading it is a published interface, and a public repository nobody imports is not.
Two other situations fall outside these rules, because their comments serve a different reader. Code written to teach — a tutorial, a README sample — narrates each line on purpose, and Knuth's literate programming is the extreme of it. Code written to be assessed, such as a take-home exercise, shows the author's reasoning because the reasoning is the deliverable. Neither register belongs in code that ships.
The four kinds of comment
A comment that is none of these four has no reason to exist.
Interface comment — sits at the declaration of a class, module or public method, and describes the abstraction: behaviour, arguments, return value, side effects, exceptions, what the caller must guarantee, and what the thing does not do. Its tags are part of it: @param and @return declare a type, are read by a documentation generator and an IDE hover, and are never accompanied by a sentence restating them. A duck type says more than a class name — [String, #read] states what the method actually requires. Object#blank?, from active_support/core_ext/object/blank.rb:
class Object
# An object is blank if it's false, empty, or a whitespace string.
# For example, +nil+, '', ' ', [], {}, and +false+ are all blank.
#
# This simplifies
#
# !address || address.empty?
#
# to
#
# address.blank?
#
# @return [true, false]
def blank?
respond_to?(:empty?) ? !!empty? : false
end
end
Implementation comment — describes what constrains a piece of code. Almost always the wrong thing to write, because the code says how it works; the exception is a property of the implementation that the code cannot show and that an obvious simplification would silently destroy. It sits inside the method body, at the line it constrains, and it carries no tags: a private method has no interface and nothing to declare. String#blank?, from the same file:
BLANK_RE = /\A:space:*\z/
class String
def blank?
# The regexp that matches blank strings is expensive. For the case of empty
# strings we can speed up this method (~3.5x) with an empty? call. The
# penalty for the rest of strings is marginal.
empty? ||
begin
BLANK_RE.match?(self)
rescue Encoding::CompatibilityError
ENCODED_BLANKS[self.encoding].match?(self)
end
end
end
BLANK_RE matches an empty string as well, so empty? || changes no result and reads as dead weight. Deleting it leaves every test green and makes the common case roughly three times slower — which is what the comment is there to prevent.
Cross-module comment — records a dependency that crosses a boundary and is therefore invisible at both ends: a provider's hard limit, a quirk of the schema, a coupling to a class in another file. It carries a pointer to where the fact is written in full, such as see doc/read-after-write.md. Ousterhout notes these are the hardest to place, because neither side is their natural home.
Data structure member — sits at a field, column or constant and says what it represents, when the name cannot carry it alone.
Directives are not comments in this sense at all. # :nodoc:, # frozen_string_literal: true and linter pragmas are addressed to a tool rather than a reader, and they stay wherever the tool needs them — tests, config and migrations included.
What earns a comment
McConnell's list of what a comment can be is short, and most of it is worthless: a repeat of the code, an explanation of the code, a marker, a summary, a statement of intent, and information that cannot possibly be expressed by the code itself. Only the last two justify th
Установить document-code в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл document-code?
Decide whether a comment belongs, and write the ones that do — in Ruby, YAML, a Dockerfile, a shell script, tests or config. Use it before adding any comment, docstring or YARD block, including one you are about to write mid-implementation, and before deleting or rewording one already there. Use it when finished code carries no documentation, when asked to document code or add YARD, and when auditing what a file or a diff already carries. Use it unprompted when a review says a comment restates the code, narrates reasoning, is outdated, or should be deleted rather than shortened. Not for prose documents — a README, a wiki page, a plan or a ticket.
Как установить скилл document-code?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл document-code запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic