Skip to content

docs: cut comments that explain standard Go, and repair detached godoc - #48

Merged
twmb merged 11 commits into
mainfrom
doc-comments
Aug 5, 2026
Merged

docs: cut comments that explain standard Go, and repair detached godoc#48
twmb merged 11 commits into
mainfrom
doc-comments

Conversation

@twmb

@twmb twmb commented Aug 5, 2026

Copy link
Copy Markdown
Owner

A comment pass over non-test source. Comment-only: no code line is touched in
any of the 11 commits, verified mechanically.

The part that actually matters

Schema.Canonical had documentation written for it that nobody could see.
A blank line between the comment and the func meant godoc ignored it, so
pkg.go.dev showed the signature and nothing else. Fixed, along with eight more
detached comments on unexported functions.

Also repairs a truncated security note in ocf: the "Memory bounds" paragraph
promised two independent limits, named WithMaxBlockBytes, and then stopped
mid-sentence — so the decompressed-size bound it was introducing went unnamed.

The cuts

Comments explaining standard Go rather than library behavior: that a nil
pointer panics, that map iteration is randomized, that ambiguous embedded
fields are a compile error, how a typed nil arises. Plus "this is useful for"
framing, worked examples of calling the function the comment sits on, and
clauses restating the sentence above them.

Comments that justify the code next to them were left alone even where they
discuss Go — why a bound is taken in float space before the int conversion,
why the depth limit is 1000, why an .IsValid() guard exists. Deleting those
invites deleting the guard they explain.

Honest scope

Net effect is only -91 comment lines (10,777 -> 10,686), which moves the
comment ratio from 37% to 36.5%. The remaining mass is not miscategorized
comments, it is long ones: 669 blocks longer than 5 lines hold 77% of all
comment lines. Reducing that needs a rule about length per decision, not about
category, and is a separate pass.

Gate

A doc round has no oracle — every test passes whichever comments you cut. So
the gate is mechanical:

git diff -U0 | grep '^[+-]' | grep -v '^[+-][+-]' | grep -vE '^[+-][[:space:]]*(//|$)'

prints nothing. go vet clean, gofmt clean, full suite and -race green.

twmb added 11 commits August 5, 2026 15:44
The dispatch arms in doResolve and checkCompat each carried a one-line
gloss of the condition immediately below ("Both unions.", "Same kind.",
"Different kinds: check promotion."), and resolveNode restated its own
doc comment at both of the sites that doc describes. None of them says
anything the code does not.
Schema.Canonical, liftFieldLogicalIntoType, tryAssignNamedRef and
validateLeaf each had their doc comment stranded above the NEXT
declaration, so godoc attached it to the wrong symbol and Canonical --
exported -- rendered with no documentation at all. Move each back and
fix the afieldComplexKeys block, which named a variable that does not
exist.
The floating "defaultAsInt32 / defaultAsInt64 / defaultAsFloat" block
documented no function -- it sat between numericDefault and a run of
unrelated helpers -- and both claims that distinguished it from
numericDefault own doc were wrong: defaultAsFloat has no string arm, and
its int64/int32 arms convert unconditionally rather than rejecting
past-mantissa magnitudes.

Also drop the second "register early so self-referencing fields..." (the
same sentence eight lines up), collapse the applyCustomTypes copy of
buildCustomWiring jsonAppliesLogical rationale to the pointer it already
carried, and cut the "setCanon=false" opener from a comment sitting on a
call that passes true.
The "Memory bounds" note lost its second limit mid-sentence ("bounds the
compressed size read off the wire (default 64 MiB), and" -> next line
starts a new topic), so the paragraph named one of the two limits it
promises. Name the decompressed bound and split the sentence.

The rest is removal: "useful for" framing on NopCloser and
WithSyncMarker, "Resolve codec." / "Apply schema evolution if a reader
schema was provided." above the lines that do exactly that, and the
history clause on WithCodec ownership paragraph -- the rule it states is
what a caller needs, not when it started applying everywhere.
Godoc that told the reader when to reach for an API rather than what it
does: CustomType "Use this when you need full control -- for example,
to map a custom Go struct to/from an Avro fixed", NewCustomType "For
example, use this to decode Avro longs into a domain-specific ID type",
SchemaCache "This is useful for Schema Registry integrations",
WithCustomType "it exists for discoverability". Each keeps whatever fact
it carried (which form reaches records, what NewCustomType infers) and
loses the advice.

setIface loses its ten-line sample of the inlined check its own prose
already describes, and typeFieldMapping ambiguity note loses "Go makes
the selector a compile error" -- true of every Go program, and not why
the error is deferred to lookup.
…ents

Same defect as the schema.go batch: valueWalkLimit, appendAvroFloat32,
findUnionBranch and inferType each had their doc stranded above the
following declaration, so godoc showed it against marshalEmitLen,
float32WireBits, unionTagTier and baseTypeForLogical instead. inferType
was left with only its ptrChain parameter note.

valueWalkLimit block also said "two orthogonal limits" above three
bullets -- now three. getString had two doc comments stacked, opening
with the same sentence twice; merged into one.
"json.Number Kind() is reflect.String" was spelled out at four sites --
the union type-name dispatcher, the enum gate, the RFC 3339 probe, and
SchemaFor Kind switch -- each re-deriving the same numeric-carrier
policy before naming its own consequence. Put the rule on the
jsonNumberType declaration every one of them compares against, and leave
each site with the part that is local to it.
Comments that named the line under them: "Handle nil / invalid values."
above !v.IsValid(), "ASCII fast path." inside the c < utf8.RuneSelf
branch, "Save position for backtracking." above savedPos, "Skip key
(string), then value.", "Deserialize each element.", "Handle UTF-16
surrogate pairs.", the struct fast-path label in deserRecord, and
deserRecordFast's no-depth-bump note, which repeats its own doc comment
verbatim two lines up.

Three fragments left over from edits: a doubled "Java's / Java's" in the
timestamp-nanos rationale, and two schema_canonical parentheticals
recording that a MarshalJSON method used to exist. atype loses the note
that its untyped string constants work wherever a string is expected.
predicate_census_test.go Q11 counts "&SemanticError{" occurrences per
file against a registered number, and the count includes matches inside
comments -- so deleting this sample as a worked example took reflect.go
from 6 to 5 and redded the guard. Put it back rather than edit the
registry, which is out of scope for a comment round.
Comment and struct-field alignment only, no semantic change. Split out
ahead of the test-file consolidation so those commits stay provably
move-only and `gofmt -l` is clean throughout.
Cut as "useful for" framing. It is not framing — it answers why anyone
would set a sync marker at all, which is not otherwise derivable from a
setter whose default is "random". Every call site in this repo is a test,
which is what the sentence says.
@twmb
twmb merged commit abb53b1 into main Aug 5, 2026
3 checks passed
@twmb
twmb deleted the doc-comments branch August 5, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant