Do you reject positional booleans in code review?

November 18, 2026 5 answers
Asked by _m86+torvexa.7

Calls like createUser(email, true, false) are hard to read without checking the signature. Do you prefer an options object, or is that overkill for something like setEnabled(true)?

Where do you draw the line, and what happens if a boolean later needs a third state?

Answers

q.671!cloverpiston

I would flag the two booleans, not setEnabled(true). The function name tells you what that single value controls. With createUser(email, true, false), neither flag is clear at the call site.

Keeping the main value positional and putting optional settings in an object is a nice middle ground. Use positive names where possible too. Cache enabled is easier to reason about than disableCache set to false.

8d~mivreno_526:

Named options help when reading a diff outside an editor, where you might not have the signature available on hover.

Reply to this answer
Trelmixa.9b

I prefer object parameters more broadly, especially when multiple arguments have the same type. Swapping two booleans or two strings can still pass a typecheck, while named properties make their roles clearer. They also make call sites easier to read without looking up the signature.

That said, an options object can become a dumping ground for optional settings. Naming the arguments doesn't eliminate the need to keep the API small.

Reply to this answer
2p~tandemfizz_803

I wouldn't ban them. An editor can show the signature, and wrapping every straightforward argument in an object adds clutter. Required positional arguments are fine when the function and types make their roles reasonably clear.

If this keeps coming up in review, agree on a team convention rather than arguing every call separately. A lint rule might help enforce an agreed rule, but it won't decide where the exceptions belong.

Reply to this answer
c.495+velumcrayon

The bigger question is what the flag represents. If it selects a mode and you can already imagine more than two modes, a TypeScript string union can name those choices directly. Separate functions can also make sense when the behaviors are genuinely distinct.

If a third state arrives later, callers and the function implementation may both need changes. How disruptive that is depends on the API and its callers, so I wouldn't assume a fixed migration cost.

_m86+torvexa.7:

That makes sense. A boolean for an on or off setting seems different from a flag that chooses between behaviors.

Reply to this answer
BrambleJet

I wouldn't let allocation concerns decide the convention by themselves. An object may have a cost, but whether it matters depends on the code and runtime. If this is a hot path, measure it before making the API harder to read for performance.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions