1: Guard Clauses
Code like this:
Or like this:
Tidy the code above to something like this:
As a reader, it's easy to get lost in nested conditions.
Code with guard clauses is easier to read & analyze because the preconditions are explicit.
Don't overdo guard clauses - a routine with sever or eight clauses is NOT easier to ready.
Last updated