Names and functions
Names that say what things are, and small functions that each do one thing. Short, shallow and with few arguments, so anyone can read them at a glance.
- Required 6
- Recommended 2
Required
Name things for what they mean
RequiredEvery name says why the thing exists, what it does and how it is used. A reader should never need a comment to learn what a name means.
Never let a name mislead
RequiredA name must never suggest a type or behaviour the code does not have. Calling a set a list, or a lookup a getter that writes, misleads every reader.
Keep functions short
RequiredKeep each function at 20 lines or fewer. A longer function nearly always does more than one thing.
Keep nesting shallow
RequiredNest blocks at most two levels deep in business logic. Deep nesting hides which branch runs and when.
Pass few arguments
RequiredGive a function at most three arguments. When it needs more, pass one named object that groups them.
Make each function do one thing
RequiredEach function does one thing at one level of detail. A function either changes something or answers a question, never both.
Recommended
Use names you can search for and say aloud
RecommendedUse whole words that people can pronounce and search for. Replace magic numbers and strings with named constants.
Split blocks into named functions
RecommendedWhen a block of code needs a moment of thought, move it into a function whose name says what it does.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/names-and-functions.