Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.26 KB

File metadata and controls

49 lines (36 loc) · 1.26 KB

Exit Early

Discourage:

if () {
  ...
  return false;
} else {
  ...
  return true;
}

Encourage:

if () {
  ...
  return false;
}

...

return true;

Reasons to exit early:

  • Process of elimination
  • Reduces cognitive load
  • Reduces indents
  • We know success will always be at the end
  • Structures your functions:
    • Validation/error handling at the beginning
    • Successful at the end

Resources

Arguments against: