Navs
Code Smells Catalog
Boolean Blindness

Last Revision — April 19, 2022

1 Min Read


  • Also Known As

    ---

  • Obstruction

    Lexical Abusers

  • Occurrence

    Names

  • Expanse

    Within a Class

  • Related Smells

    - Uncommunicative Name (family)
    - Magic Number (family)
    - "What" Comments (causes)

  • History

    Marcel Jerzyk in thesis (2022): "Code Smells: A Comprehensive Online Catalog and Taxonomy"

Boolean Blindness

In the Haskell community, there is a well-(un)known question about the filter function - does the filter predicate means to TAKE or to DROP (check example)? Boolean Blindness smell occurs in a situation in which a function or method that operates on bool-s destroys the information about what boolean represents. It would be much better to have an expressive equivalent of type boolean with appropriate names in these situations. For the filter function, it could be of type Keep defined as Keep = Drop | Take.

This smell is in the same family as Uncommunicative Names and Magic Numbers.

Problems:

Comprehensibility

Neither in real life one can answer just yes/no without ever confusing interlocutor to every single closed question that may possible.

Example

Ambiguity of Boolean

data Bool = False | True
filter :: (a -> Bool) -> [a] -> [a]

Meaningful Boolean

data Keep = Drop | Take
filter :: (a -> Keep) -> [a] -> [a]

Refactoring:

  • Introduce New Type

Sources
  • [Origin] - Marcel Jerzyk, "Code Smells: A Comprehensive Online Catalog and Taxonomy" (2022)