style: Params struct required even for single arguments

Only exception: stupidly obvious single args (featureflag.New(true)).
When in doubt, use Params.
This commit is contained in:
user
2026-03-17 19:57:28 -07:00
committed by clawbot
parent e72b2d3522
commit 4c643d1aa2

View File

@@ -157,13 +157,14 @@ last_modified: 2026-02-22
`server`. `util` is banned.
1. Constructors **must** take a `Params` struct (or `ThingParams` when
`NewThing()` is used). Positional arguments for constructors are an endless
source of bugs — they make call sites unreadable, invite wrong-order errors
that the compiler can't catch when types coincide, and force every caller to
update when a new field is added. The only exception is a constructor that
takes exactly one argument whose meaning is obvious from context (e.g.
`New(ctx)` or `FromBytes(b)`). Two or more arguments → use a Params struct,
no exceptions.
`NewThing()` is used), even for a single argument. Named fields in a Params
struct are always clearer than positional arguments. Positional arguments
for constructors are an endless source of bugs — they make call sites
unreadable, invite wrong-order errors that the compiler can't catch when
types coincide, and force every caller to update when a new field is added.
The only exception is when the single argument is stupidly obvious from
context — e.g. `featureflag.New(true)` or `thing.NewFromReader(r)`. When in
doubt, use a Params struct.
1. Use `context.Context` for all functions that need it. If you don't need it,
you can pass `context.Background()`. Anything long-running should get and