Write Code Comments with AI

To write code comments with AI, paste the function or module into @vustbot in Telegram and ask for docstrings or inline comments that explain the why, not the what. Works per snippet — the bot reads only what you paste, not your repository — and you get commented code back to copy over the original.

The hard part of commenting isn't writing — it's that the person who understands the code least right now is you, six months later. A model reading your function cold is a decent proxy for that future reader: what it can't infer is exactly what needs a comment.

Open @vustbot in TelegramPay per action · no signup beyond Telegram

What the AI does in this scenario

  • Paste a function → same function back with a docstring and targeted inline comments
  • Format on request: JSDoc, Python docstrings (Google/NumPy style), Javadoc, rustdoc
  • Flags lines it can't explain — those gaps are where YOUR context is required
  • Comment-only diff on request: keeps your code bytes untouched
  • Per-snippet spark pricing — comment the gnarly 10%, skip the obvious 90%

Worked example: write code comments with ai

Input

def backoff(attempt, cap=30.0): return min(cap, random.uniform(0, 2 ** attempt * 0.1)) Add a docstring + inline comments, Google style. Context: retry delays for a flaky payment API.

Output

The same two-line function returned with a Google-style docstring — """Full-jitter exponential backoff for payment-API retries. Uses full jitter (random 0..cap) rather than plain 2^n so parallel clients don't retry in lockstep after an outage. Args/Returns…""" — plus one inline comment on the `0.1` base-delay factor. Code itself byte-identical.

How to write code comments with ai — step by step

  1. 1
    Paste the code with one line of context

    The function plus "this is retry logic for a payment API" — that context line is what turns generic narration into a real why-comment. The bot sees no repository, so the context you type is all the context there is.

  2. 2
    Name the format and the density

    "Google-style docstring, inline comments only where the intent isn't obvious from the code" — the density clause matters most. Without it you get a comment per line, which is worse than none.

  3. 3
    Fill the flagged gaps, then diff before replacing

    Where the model says "unclear why this constant is 0.1" — that's a comment only you can write; write it. Then diff the returned code against your original to confirm only comments changed before pasting it back.

AI vs doing it manually

The comments that matter most — "this looks wrong but fixes JIRA-482, don't simplify" — can only come from you, because they encode history the code doesn't contain. AI is genuinely better at the layer below: accurate parameter docs, return-value descriptions, and naming the algorithm your code implements ("this is full-jitter backoff") when you'd have written "calculates delay". The best workflow is a division of labor: let the model draft the mechanical layer and flag what it can't infer, then spend your minutes writing only the history-and-intent comments in those gaps.

The prompt to copy

Add comments to this [LANGUAGE] code: [PASTE CODE]. Context: [WHAT IT'S FOR, ONE LINE]. Format: [JSDOC/GOOGLE DOCSTRING/JAVADOC]. Rules: docstring for each public function; inline comments ONLY where intent isn't obvious from the code; explain why, not what; do not change any code — return it byte-identical with comments added; list anything you couldn't infer so I can document it myself.

Frequently asked questions

Related in Developers

Try it on your real task

The welcome bonus covers a first run — send the prompt above with your own facts and judge the output yourself.

Open @vustbot