Code quality and technical debt

Boolean parameter

Also known as Boolean parameter, Boolean parameter in software engineering

By WeavePublished 1 min read

Definition

A function argument whose true or false value selects behavior or a mode.

What it means

Boolean parameters can make call sites ambiguous and cause one method to serve multiple responsibilities. A call such as render(true) forces readers to find the meaning of the flag. Named options, separate methods, or domain-specific types can make intent visible when the modes differ materially.

Example

A notification method accepts send(message, true), where the flag controls immediate delivery. Replacing it with explicit delivery options lets callers state whether they want immediate or queued behavior.

Limitations

A boolean can be the clearest representation for a genuine binary property, especially in a private helper. Replacing every flag with a type can add ceremony without improving meaning. Consider call-site readability and branch behavior.

How to use the signal

Inspect every call site before replacing a flag, since the clearest alternative is the one that makes the selected behavior explicit.

Weave can help show whether boolean-heavy changes attract review iteration or follow-up fixes. The signal comes from code analysis, while Weave provides the workflow evidence needed to prioritize a refactor.

How this relates to Weave

Weave can help show whether boolean-heavy changes attract review iteration or follow-up fixes. The signal comes from code analysis, while Weave provides the workflow evidence needed to prioritize a refactor.

Explore Engineering intelligence

Sources and further reading

  1. SonarSource code metrics and analysis documentation