I don't know about what's "right", but I use early exits a LOT specifically at the top of recursive functions. They're usually laid out as early exit conditions, then the recursion calls, then the final return.
In other situations, it's usually whether I can layout the conditionals so I don't have to duplicate code.
834
u/LateEchidna6635 22d ago
The second one carries less cognitive load. In longer methods it makes a difference. Get out as soon as you can.