Agent Wranglers

ARC-12Avoid

Misleading names

Never give a name that suggests a type or behaviour the code does not have. Calling a set a list, or a lookup a getter that writes, misleads every reader.

How to do it

Only use a type word, such as List, Map or Set, when the value is that type. Prefer a plain plural, such as customers. Keep names that differ only slightly, such as account and accounts, far apart or rename one. A function named get must not change anything. Keep commands and questions apart, as Make each function do one thing says.

Examples

Python example

# Bad: a set called a list, and a getter that writes
customer_list = {"ada@example.com", "bo@example.com"}
def get_order(order_id): orders.mark_viewed(order_id); return orders.find(order_id)

# Good
customer_emails = {"ada@example.com", "bo@example.com"}
def find_order(order_id): return orders.find(order_id)

TypeScript example

// Bad: a set called a list, and a getter that writes
const customerList = new Set(['ada@example.com', 'bo@example.com']);
function getOrder(id: string) { orders.markViewed(id); return orders.find(id); }

// Good
const customerEmails = new Set(['ada@example.com', 'bo@example.com']);
function findOrder(id: string) { return orders.find(id); }

How to check

A custom lint rule fails a name containing List, Map or Set whose declared type is another kind of collection. It also fails a function named get or find that calls a write method, such as save, update or delete.

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/no-disinformation">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.