I’ve used three early returns in 25 years, all in the same circumstances: nested loops in supremely performance-critical code. With a huge comment box at
- the top of the function
- the bottom of the function
- at the early return itself
notifying the reader that I am doing something absolutely horrible for a good reason. I consider it abominable structure.
If you regard deep indentation as worth it, I would want to know why; if the indentation is really that deep then the function probably needs to be broken up.
We agree on keeping functions small. You’ll never convince me on early returns; to me nothing says “junior programmer” like an ER.
On the one hand, yes, senior people who pay attention to what they’re doing can get away with them, e.g. JGO because an invalid parameter was passed in rather than indent four levels for four parameter checks. But I would forbid them until people had deeply internalized that JGO is bad because I don’t want people thinking that way, looking for excuses to bail out.
I’m not sure what dyslexia has to do with it. That’s a spelling problem and your post looks correctly spelled to me.
Anyway it’s the opposite for me. Being able to see scoping levels is rich information for me. I work on 24–27" monitors and I don’t mind ten levels of indentation but I rarely end up with more than five.
I was in an interview once. I could see the guy’s code across the room but not read it, just see that it was mostly flush left. I asked him “you’ve reached a stage where every time you fix a bug you get new bugs elsewhere, haven’t you.” His eyes got big. “How did you know!” I pointed to his monitor. “You’re using early returns.”
The other reason is that an early return is likely to include some error handling, even if it’s only tracelogging (which I use nearly everywhere). So the first screen or screens of the function are going to be tons of error handling and every point where there can be an error is going to interrupt the reading with more of the same.
I would rather read the path of correct execution, all in a row and together, and do all error-handling in the else clauses. That’s the way I’ve worked for decades. Since you do end-of-line braces that would be hard for you.