Commenting style
The people reading this code are high-school students, many with little or no Java: assume a novice programmer. Comments are how they learn what each part does and WHY we wrote it that way. Every file follows this guide.
Write in plain, everyday, non-technical language. Say “the robot waits here” instead of “this blocks the thread”. Say “a number that can change” instead of “a mutable field”. When you cannot avoid a technical word (encoder, PID, servo), explain it in a few everyday words right there, or point to the page that explains it.
Point to other files and docs when they explain more: “See docs/modules/drive.md”, “Tutorial 07 explains PID step by step”, “The signs are in docs/conventions.md”, “This is the same idea as SafeMotor (safety/SafeMotor.java)”.
The rules
Section titled “The rules”-
Explain WHY, not only WHAT.
// clamp the powersays what.// clamp: a motor only accepts -1..1, and NaN (a bad sensor reading) would make it jumpsays why. -
Plain, short, non-technical sentences. Everyday words. Explain any technical word the first time in everyday terms (PID, encoder, tick, lambda, edge…), or link to the doc that explains it.
-
One comment per idea, on the line above the code it explains (or at the end of a short line).
-
Units and signs wherever a number appears: ticks, inches, degrees, seconds, milliseconds; “positive = left (counterclockwise)”.
-
Always write down safety reasons: why a motor is stopped, why a limit exists, why we never wait.
-
Java ideas that a beginner would not know get a short, everyday-language note the first time they appear in a file (for example “
() -> ...is a small piece of code we hand over to run later”). These ideas are: lambda() -> ..., method referencelift::stepUp, ternarya ? b : c,final,static,interface,@Override,try/finally,synchronized,volatile, generics<T>, enum. In examples and tutorial programs (rule 9) that note goes in the docs next to the code (a code annotation or the text), not in the file. -
Do not comment the obvious.
i++and simple getters need nothing. A comment that only repeats the code is noise. -
Section headers in long classes:
// ---- Setup ----,// ---- Every loop ----. -
Examples and tutorial programs keep only the essential comments (decided 2026-10-23): what a line is, units, “= the name in the robot configuration”, “measure this”, a safety warning, and a
more: https://crossbotics.com/...link where it helps. At most 3//lines in a row and 8 lines of/** */(tools/check_docs.pychecks it). Why: teams copy these files, and long explanations get in the way of their own code. The WHY (rules 1 and 6) goes in the docs, next to the code that shows it: as a code annotation or in the text. -
Keep comments true. When code changes, its comments change in the same commit.
-
Say it once (docs code boxes). Each part has its own job:
- the code comment says WHAT the line is, in one line;
- the (+) note (code annotation) says WHY, for that one line only: at most about 3 sentences, and no numbers the text or a table already gives;
- the text under the box says what the step does and what to check.
Never write the same sentence twice (in the comment and the note, or the note and the text). Explain a note that every recipe would repeat (what
.part(...)does) once, where it first appears.
Code annotations in the docs
Section titled “Code annotations in the docs”A docs code box can explain a line without a long comment in the code. Add a marker (1)! at the end of
the line’s // comment (or // (1)! alone after the code). Then put a numbered list right under the box,
one item per marker, in order:
```java title="Robot.java"lift = add(Lift.slide("lift").part("gobilda-5203-435")); // the lift (1)!```
1. "lift" is the motor's name in the robot configuration. Its numbers: `Tunables.Lift`.On crossbotics.com each marker becomes a small (+) button that opens its item. The site hides the list
itself, and the Copy button copies the code without the markers. On GitHub the marker and the list show as text.
The markers are only in the docs: tools/check_docs.py takes them out before it compares a box with its
Java file. --fix-cookbook keeps them on the lines that did not change.
Format
Section titled “Format”- Javadoc (
/** ... */) on every public class and method: what it does, parameters (with units and ranges), what it returns, and a short example when useful. //comments inside methods for the steps and the reasons.- Line length: about 110 characters.
Something wrong on this page? Tell us with a short GitHub form.