Readable Python Chapter 5 · NamingContents

Naming

Names from the domain, used consistently.

RP08

Name things with domain words, and use the same word for the same thing everywhere.

A codebase is a vocabulary. If "request", "job", "query" and "generation" all mean the same thing, every reader has to learn four words for one idea, and will suspect they mean four different things.

Build a small glossary

Keep a short list of the core nouns of your system, with one-line definitions, in the README or at the top of the main module. For a text-generation server it might be:

WordMeansNever call it
Requestwhat a client submitted: a prompt and its limitsjob, query, task
Sequencean admitted request while it's being generatedrequest (it has state now), generation, stream
Batchthe sequences run together in one forward passgroup, bundle, micro-batch
Stepone forward pass that adds one token to each sequenceiteration, tick, round
Workera process that owns one GPUreplica, node, executor

Then hold the line in review. New words need a reason.

Guidelines

Functions are verbs, values are nouns

admit(request), retire_finished(), detokenize(tokens). Booleans read as questions: is_finished, has_free_slot, can_accept().

Say what it is, not what type it is

Before
seq_dict = {}
id_list = []
data = model.forward(input_map)
tmp = tokenizer.decode(data)
After
running_by_id = {}
waiting_ids = []
logits = model.forward(batch)
text = tokenizer.decode(token_ids)

Units in the name when they aren't obvious

timeout_s, kv_cache_bytes, latency_ms, max_new_tokens. This prevents a whole class of bugs that types don't catch.

Length matches scope

A loop index over three lines can be i. A module-level constant read in five files needs a full name. Avoid abbreviations except universal ones (id, url, gpu, kv).

Private means private

A leading underscore says "not part of this module's interface". Use it for that, and don't import _names from other modules. If another module needs it, it's public; drop the underscore.

No framework words for domain things

Manager, Handler, Processor and Helper say almost nothing. Prefer what the thing actually does: Scheduler, BlockAllocator, Detokenizer.