wordfor

guard clause

noun

Software design

  1. A check at the top of a function that returns or throws early for invalid or special cases, so the main logic is not nested. Two guard clauses for a missing user and an expired session flattened four levels of nesting.

In plain words

  • too many nested if statements
  • return early
  • the code is indented too deep
  • handle the bad cases first

See also fail fast edge case

Find similar words