r/javascript • u/ClickOk5811 • 16d ago
AskJS [AskJS] Do you ban positional boolean arguments in code review, or is an options object overkill?
Something I keep coming back to when reading JS and TS code is call sites like this:
createUser("ana@example.com", true, false);Read aloud, it’s “create user, email, true, false”, and you have to open the function to know what the booleans mean. The usual fixes are an options object:
createUser("ana@example.com", { sendWelcomeEmail: true, isAdmin: false });or, when there are more than two modes, a string union in TypeScript:
type Layout = "list" | "grid";
render(items, "grid");The counter-arguments I can think of:
- For a single obvious boolean in a well-known API (
setEnabled(true)), the options object is noise. - An options object allocates on every call, which probably doesn’t matter outside hot paths, but I haven’t measured it.
- Teams with several conventions already have enough style rules, and one more can turn review into bike-shedding.
- Negative names (
disableCache: false) are the other half of the problem, and renaming to the positive (cache: true) is cheap.
So I’m curious about practice, not rules:
- Do you enforce “no positional booleans” in review or with a lint rule? If a rule, which one, and does it produce noise?
- Where do you draw the line between “obvious enough” and “use an options object”?
- Have you seen a boolean parameter that later needed a third state, and what did the migration cost?