Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
5.4 KiB
Naming (STRA-338)
Whoever comes back to this code in a month must understand what a thing is and what it is for from its name, without reading the
body. This page is the rule set (owner order of 2026-11-08), a "bad -> good" table taken from our own code, and the review checklist
used for every change. Domain words are defined once in docs/glossary.md; use them exactly.
Sources: Robert C. Martin, Clean Code, ch. 2 "Meaningful Names"; Rust API Guidelines, "Naming" (RFC 430 casing and the as_ / to_ /
into_ conventions, https://rust-lang.github.io/api-guidelines/naming.html); John Ousterhout, A Philosophy of Software Design,
ch. 14 "Choosing Names" (https://lamb.github.io/a-philosophy-of-software-design/choosing-names.html); the SSW rule "avoid generic
names" (https://www.ssw.com.au/rules/avoid-generic-names).
Checklist (paste into a review; every item is a yes/no)
- Intent. The name says what it is, what it is for and how it is used, without a comment to explain it.
- Precision. No
status,flag,data,info,tmp,val,ret. Say which:is_/has_/can_for booleans, so thattruereads as an obvious statement (is_resident, notflag). - One term per concept, project-wide, from the glossary (expert, tier, slot, round, window, draft, commit, prefill, decode); never one word for two different things, never two words for one thing.
- Banned vague words in type, module and function names:
Manager,Helper,Util(s),Handler,Processor,Service,Data,Info,Misc,Common,Base,Impl,Wrapper,Stuff, and numbered suffixes (_2,_N,w01). (Servicestays where it is the domain word, for example the NPU service process; say so in the doc comment.) - Length follows scope.
iandjonly in a loop of about three lines; no abbreviations (qkv,rms,idxare allowed only as an established domain term listed in the glossary). Units are part of the name:timeout_ms,size_bytes,rate_tokens_per_s. - Role, not type.
selected_experts, notvec_of_expertsorv;bank, notarc_vec. - Rust conventions (RFC 430):
UpperCamelCasetypes,snake_casefunctions and modules,SCREAMING_SNAKE_CASEconsts; acronyms as a word (Gpu,Uuid,Kvin a type name); noget_prefix for a plain getter (slot.owner());as_is free and borrows,to_is costly and allocates,into_consumes; constructorsnew,with_<what>,from_<what>; a builder ends in.build(). - Shape by kind. A module or file is a noun for what it holds (
expert_slot_cache.rs); a function is a verb phrase (evict_cold_slots); a type is a noun. A file name never repeats a type with a mechanical suffix (_fn,impl_,_2): the architecture gate rejects new files namedimpl_*.rs,*_fn.rsand*_<N>.rs(mechanical_namesinarchitecture.json). - Searchable. A name is unique enough to grep; no magic numbers: a named constant carries the unit
(
const MTP_RING_CELLS: usize = 20480;). - If you cannot name it, split it. A function or type without a short honest name does two things. A function with more than 5
parameters is the same signal: give the arguments an owner (a method on it) or a DTO with a domain name, never
Args,Params,Ctx,Opts,Input. - Documented. Every new DTO and public function has a 1-2 line doc comment: what it is and why it exists.
Bad -> good (our code)
| Where | Bad | Good | Rule |
|---|---|---|---|
cuda-driver/src/bringup_trace_enabled_fn.rs |
file ..._fn.rs |
bringup_trace_enabled.rs |
8 |
cuda-driver/src/q6_k_shape_fn.rs |
file ..._fn.rs |
q6_k_shape.rs |
8 |
qwen_forward/original_serve_stack/impl_originalservestack_4.rs |
file named after the type and a counter | decode_steps.rs (the one child that already has this name shows how) |
4, 8 |
.../impl_originalservestack_2_2.rs |
impl_, _2_2 |
what the impl block does: request_accounting.rs |
4, 8 |
engine-qwen35-cuda/.../qwen4exp_mtp/impl_mtpweights.rs:58 |
let mut data = Vec::new(); |
let mut expert_chunk_bytes = Vec::new(); |
2, 6 |
bringup_trace_enabled_fn.rs:108 |
fn set(&self, v: bool) |
fn set(&self, is_enabled: bool) |
2 |
native-cpu-expert/.../alloc_fn.rs |
struct Target { x, w } |
QuantTarget { values, weights } (renamed in the params pass) |
4, 6 |
gptoss/src/weights.rs:43 |
pub bk: &[f32] |
pub key_bias: &[f32] |
5 |
| any function with 6+ arguments | fn run(a, b, c, d, e, f) |
split the work, or fn run(&self, request: ExpertSlotRequest) |
10 |
| any new DTO | struct Args { .. } |
struct LaunchGeometry { grid, block, shared_bytes } |
3, 4, 10 |
| config | timeout: u64 |
timeout_ms: u64 |
5 |
| magic number | if cells > 20480 |
if cells > MTP_RING_CELLS |
9 |
| getter | fn get_len(&self) |
fn len(&self) |
7 |
| conversion | fn to_str(&self) -> &str |
fn as_str(&self) -> &str (to_ only when it allocates) |
7 |
For tooling
scripts/dev/rustsplitnames the modules it creates after what they hold (foo,thing_methods,display_for_thing,thing_methods_from_<method>); a taken name gets a word (_more), never a number.- The architecture gate rejects new mechanical file names and counts the existing ones down to zero
(
architecture-baseline.json,mechanical_names). - The limits gate caps a function at 5 parameters,
selfincluded (docs/architecture/limits-gate.md).