Agent Wranglers

ARC-11Recommended

Name things for what they mean

Every 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.

How to do it

Name values for what they hold, such as unpaidInvoices, not data or list2. Name functions for what they do or return, such as sendReceipt or isOverdue. Name booleans as questions, such as hasStock. Use the same names in the database, as Name things the same way everywhere says.

Examples

TypeScript example

// Bad
const d = getData(u);
// Good
const unpaidInvoices = findUnpaidInvoices(customer);

Python example

# Bad
d = get_data(u)
# Good
unpaid_invoices = find_unpaid_invoices(customer)

How to check

A linter bans vague names, such as data, info, tmp, obj and foo. Examples are ESLint id-denylist for JavaScript and Pylint bad-names for Python. A length rule fails names shorter than two characters outside loop counters, such as ESLint id-length with an exceptions list.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/names-and-functions/intention-revealing-names">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.