Agent Wranglers

ARC-29Avoid

Passing null to mean a default

Never call a function with null to mean "use the default" or "skip this". Give the function a clear variant or an options object instead.

How to do it

Split a function that takes an optional flag into two named functions. For many optional settings, take one object whose fields have defaults. Reject null at the start of public functions. The same reasoning applies to results, as Return empty collections and one agreed absent value says.

Examples

JavaScript example

// Bad: what does null mean here?
sendInvoice(order, null, null, true);

// Good: the call says what it does
sendInvoice(order, { copyTo: accountsEmail });
sendInvoiceReminder(order);

Python example

# Bad
send_invoice(order, None, None, True)
# Good: keyword arguments with defaults, and a second function
send_invoice(order, copy_to=accounts_email)
send_invoice_reminder(order)

How to check

Strict types reject null for parameters that do not allow it. Examples are TypeScript strict, PHP native types without ?, and mypy --strict. Reviewers fail calls that pass a literal null.

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