style: Clarify function naming and args

5172b0d3ff7dee5e005a5adda9a35311bcc061fb
Require function names to describe their return values so callsites
expose the returned concept.

Assisted-by: Codex:gpt-5.6
Alexis Sellier committed ago 1 parent 38e35d94
STYLE +3 -0
43 43
44 44
* Name fields after their role in the abstraction, not after an incidental implementation detail.
45 45
* Name callbacks after what the caller is asking them to do.
46 46
* When wrapping a lower-level operation, choose a name that distinguishes the wrapper from the operation it delegates to.
47 47
* Keep function names short, but not at the cost of hiding important context.
48 +
* Functions should be named according to what they return, like `fn diff_document(...) -> Result<DiffDocument, Error>`.
48 49
49 50
HELPERS
50 51
51 52
* Do not create small helper functions when they are only used in one place.
52 53
* Generally avoid one-line helpers, unless it's a complicated line.
85 86
86 87
FUNCTIONS
87 88
88 89
* Prefer methods on types to free functions.
89 90
* Avoid private helpers that are only used once.
91 +
* Functions should take the narrowest types needed as arguments, eg. don't take
92 +
  `&User` if you only need `&UserId`.
90 93
91 94
TESTS
92 95
93 96
* Use `unwrap` in tests, not `expect`.
94 97
* Define tests in a module called `tests`.