Agent Wranglers

ARC-37Recommended

Make the order of calls impossible to get wrong

If methods must run in a set order, the code must enforce it. Never rely on callers remembering to call init() first.

How to do it

Build objects fully in the constructor, so there is no "not ready yet" state. Let each step return the object for the next step, so the next call only exists after the first. Or wrap the sequence in one function that runs every step in order. Orders show the pattern in Move orders through a fixed set of states.

Examples

Python example

# Bad: forget connect() and send() fails at run time
client = MailClient()
client.connect(host)
client.send(message)

# Good: you cannot get a client without a connection
client = MailClient.connect(host)
client.send(message)

TypeScript example

// Good: each step returns the only thing you can do next
const receipt = await cart.checkout(address).pay(card);

How to check

A test creates the object and calls each public method straight away. Each call either works or cannot be written, because the type does not have it.

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