> For the complete documentation index, see [llms.txt](https://engineering.umh.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://engineering.umh.app/engineering/development-process/how-to-build/coding-standards/code-quality/code-comments.md).

# Code comments

What a doc comment and an inline comment are for, in every language.

Owner: Jeremy

Every exported function, type and component has a doc comment. Inside the code, a comment is the last resort.

This page comes after [Abstractions](/engineering/development-process/how-to-build/coding-standards/code-quality/abstractions.md) and [Readability](/engineering/development-process/how-to-build/coding-standards/code-quality/readability.md). A comment holds what is left.

## Rules

* Every exported function, type and component has a doc comment in the form its language expects.
* We write an inline comment only for what the code cannot say after we [made it explain itself](/engineering/development-process/how-to-build/coding-standards/code-quality/readability.md#make-the-code-explain-itself).

## Doc comments

**A doc comment is for the person who uses the code.** It says what a function, type or component does. It does not repeat the name or the types.

The form depends on the language:

* Go: [Go: code comments](/engineering/development-process/how-to-build/coding-standards/languages/go/go-code-comments.md), our own page.
* TypeScript: the JSDoc rules in [Google's style guide](https://google.github.io/styleguide/tsguide.html#comments-documentation), which our [TypeScript](/engineering/development-process/how-to-build/coding-standards/languages/typescript.md) page follows.
* Svelte: [the Svelte docs on documenting components](https://svelte.dev/docs/svelte/faq#How-do-I-document-my-components).

## Inline comments

**An inline comment is for the person who changes the code.** It holds what is left after the code explains itself. [Readability](/engineering/development-process/how-to-build/coding-standards/code-quality/readability.md#make-the-code-explain-itself) describes how to get there.

**An inline comment sits next to the step it explains.** A long comment above a function that lists every step makes the reader hold the whole list in mind.

**An example often says more than a description.** A field for a message to the user can say: this is the message the frontend shows, for example "CPU limit reached".

**A field comment can name who reads the field.** A paragraph about a status field's wire format was replaced by one line: "this is read by the Management Console frontend and ProtocolConverterService.IsResourceLimited".

**Code that follows an outside format links to its documentation.** Code that parses the Linux cpuset format links to the kernel's documentation of that format. The comment then only says what we expect from the input.

## What goes elsewhere

**A comment describes the code as it is now.** Why the code has this shape belongs in the comment. How it got there belongs in the commit message, as [Readability](/engineering/development-process/how-to-build/coding-standards/code-quality/readability.md#give-context) describes.

**A comment that discloses a known defect links its bug ticket or** [**tech-debt ticket**](/engineering/development-process/how-to-build/tickets/tech-debt.md)**.** The ticket is where someone picks the defect up.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://engineering.umh.app/engineering/development-process/how-to-build/coding-standards/code-quality/code-comments.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
