jargon

Design patterns·Who calls whom, and when

the invalid cases return in the first four lines, and the rest of the method is not indented at all.

Guard clause

Also calledearly return, bouncer pattern, precondition check

Handling exceptional or invalid input with an immediate return at the top of a method, so the main path is unnested. It is the standard cure for deeply nested conditionals and makes the preconditions readable as a list. It is the smallest structural change in this corpus and the one most likely to be worth making in code you are reading right now.

Commonly confused with