Stop Naming Your Variables "Flag": The Art of Boolean Prefixes (2025)
11 hours ago
- #naming-conventions
- #best-practices
- #clean-code
- Boolean names should be clear questions with values answering 'yes' or 'no'.
- Use four prefixes for 99% of boolean naming: IS (state), HAS (containment), CAN (capability), SHOULD (intent).
- Avoid negative names like 'isNotEnabled' to prevent confusion and double negatives.
- Boolean traps in parameters should be fixed by splitting methods, using enums, or config objects.
- Watch for antipatterns like vague names, grammar mismatches, and multi-purpose booleans.
- Good naming is an act of empathy, aiding future maintainers, including yourself.