---
title: "Make each function do one thing · Agent Wranglers"
url: https://agentwranglers.se/playbook/architecture/names-and-functions/one-thing-per-function
updated: 2026-10-20
licence: "All rights reserved"
---

# Make each function do one thing

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Names and functions](https://agentwranglers.se/playbook/architecture/names-and-functions)
- Rule: Each function does one thing at one level of detail. A function either changes something or answers a question, never both.
- How: 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.
- 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.

Example:

```js
// 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);
}
```

```python
# Good in Python: each step has its own named function
def handle_signup(form):
    account = create_account(validate_signup(form))
    send_welcome_email(account)
```

**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`.

- Previous: [Pass few arguments](https://agentwranglers.se/playbook/architecture/names-and-functions/few-arguments)
- Next: [Split blocks into named functions](https://agentwranglers.se/playbook/architecture/names-and-functions/extract-and-name)
- [Names and functions](https://agentwranglers.se/playbook/architecture/names-and-functions)
