Names and functions Required
Make each function do one thing
Each function does one thing at one level of detail. A function either changes something or answers a question, never both.
How to do it
If you can describe a function only with "and", split it. Keep high-level steps and low-level details in separate functions. Commands return nothing, and queries change nothing. A command that creates a record may return its new ID.
Example
// Bad: checks, saves and emails in one place
function handleSignup(form) { /* validate, insert row, send welcome email */ }
// Good
function handleSignup(form) {
const account = createAccount(validateSignup(form));
sendWelcomeEmail(account);
}
# Good in Python: each step has its own named function
def handle_signup(form):
account = create_account(validate_signup(form))
send_welcome_email(account)
How to check
A review question asks whether each function's name describes everything it does. A function named as a query, starting with get, find, is or has, returns a value and writes nothing. Tests for a query never need to check a side effect.
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/one-thing-per-function.