Skip to main content
1 of 3
CJ Dennis
  • 669
  • 6
  • 16

Is there a use case for boolean parameters?

Most programmers (including me) believe that methods with a boolean flag parameter should be refactored into two methods without the flag parameter. Are there any use cases for a boolean parameter where it isn't a flag? I haven't been able to think of any. However, just because I can't think of an example doesn't mean that one doesn't exist.

I'm after an example where at least 90% of programmers would agree that a boolean parameter makes the most sense, produces the cleanest, most elegant code, etc. That is to say, the use case should be fairly uncontroversial. The method should use the boolean value itself and not simply pass it through to some other method. If you believe there can never be such an example, please explain your rationale.

CJ Dennis
  • 669
  • 6
  • 16