I prefer the second way. If you always return out of a function as soon as possible, you prevent deeply nested code. This means you can forget about all the weird edge cases for most of your function, because they've clearly already returned. It makes your code easier to reason about, which is important. Here is more info.