Coding Tactic: Early Returns
Whenever you find the bulk of a function needs to be nested inside one or more if
conditions, consider using early returns instead.
You get a couple benefits for doing this. The exception condition and it’s effect are grouped together. Also, for the rest of the function, you can forget about that situation and focus on the behavior you want.
Here’s an example of modifying some code to use early returns instead: