Quick inline comments
Inline comments are best for short clarifications of non-obvious code paths, intent, or one-off details. Keep them concise and place them directly above or beside the line they explain. Example — a simple FastAPI route with an inline comment:- Minimal maintenance cost for small clarifications.
- Helpful for explaining why a choice was made (not what the code does).
- Ideal for temporary notes during refactors.
- Don’t restate obvious code (e.g.,
i += 1 # increment i). - Avoid long prose—use docstrings for public APIs and modules.
Generate docstrings with a code assistant
For public functions, modules, or endpoints, prefer docstrings. They integrate with editors, documentation generators, and type-checking tools. You can use a code assistant (like GitHub Copilot) to bootstrap docstrings, but always review and adapt the generated text. Example of an assistant-generated docstring for a FastAPI route:Always verify assistant-generated docstrings against your actual code (function signatures, Pydantic models, and repository functions). Generated text is a helpful starting point, not an authoritative source.
- Prompt clearly (e.g., “Write a concise Google-style docstring describing parameters, return value, and a usage example”).
- Confirm argument names, types, and return shapes — assistants sometimes use stale context.
- Choose a docstring style (PEP 257, Google, NumPy) and keep it consistent across the project.
When models and code drift — verify and correct
Assistants may generate docstrings that reference outdated fields. If your Pydantic model changed, update both the route and the docstring to accurately reflect the request schema and repository behavior. Example Pydantic request model:get_fake_data(count: int) -> list, update the route to call it correctly and reflect that in the docstring:
locale, change the call to get_fake_data(request.count, request.locale) and update the docstring accordingly.
Generating README.md with a code assistant
Code assistants are useful to bootstrap repository-level documentation like README.md. Use a clear prompt (for example: “Generate a README for this FastAPI-based fake data generator, including setup, usage, and examples”) and then refine the output to reflect your actual repository structure and commands. Example README scaffold an assistant might create (refine to match your repo):Quick comparison: comments, docstrings, and README
Practical tips and workflow suggestions
- Use inline comments for small, local clarifications and docstrings for public-facing APIs.
- Maintain a short review step when using assistants: check types, argument names, and response structure.
- Keep docstrings consistent (pick one style: Google, NumPy, or PEP 257).
- For API projects, document request model fields and response payload shapes; it’s helpful for consumers and for tools generating OpenAPI specs.
- Add automated checks to catch drift: type hints, unit tests for endpoints, and CI tasks that run a subset of integration checks.