Skip to content
AI Stack Nest
IntermediateLesson 6 of 7 · 2 min read

Documentation and Comments with AI

AI assistants can generate clear documentation and comments quickly, saving time on a task most developers put off.

Documentation and inline comments are tasks most developers put off, and they tend to get written quickly and badly when they are written at all. An AI assistant can generate solid first drafts of both, faster than you can type.

Writing function documentation

Paste in the function and ask for a docstring in your preferred format: JSDoc, Python docstrings, or plain comments. The result is usually accurate for straightforward functions. For complex ones, check that the parameter descriptions match the actual types and that the return description is correct.

Writing inline comments

Ask the assistant to add comments to a block of code explaining what it does. The result is often over-commented: comments that just restate what the code obviously does. Edit these down. The comments worth keeping explain why a decision was made, not what a line does. These are harder for the tool to write, because the reason usually lives in your head, not in the code.

Writing README sections

Describe a module or project and ask for a README section. This works well for standard sections: installation steps, usage examples, configuration options. The assistant produces clean prose that you adjust with your project's specific details.

A concrete example

A developer has a utility module with eight functions and no documentation. They paste each function into the assistant and ask for a one-paragraph description and a parameter list. The result for six of the eight functions is usable with minor edits. For the two complex ones, the description is slightly off and needs a manual rewrite. Total time saved: about forty minutes compared to writing from scratch.

Try it

Pick three functions in a project you are working on that have no documentation. Ask the assistant to write a short docstring for each one. Read each result and edit anything inaccurate. Notice how much faster this is than writing from scratch.

Quick check

What is a useful AI prompt for documentation?

Quick check

What kind of comment is most valuable and hardest for AI to write?

0 of 7 lessons done in this track