Programming Patterns I Like
I&#x27;m very surprised that early returns are still commonly used and advocate in 2019. In my opinion, they are obviously terrible. I&#x27;ll try to convince you.<p>First the practical, in my experience, a big function with many early returns has a bug or has a convoluted logic, 100% of the time. I&#x27;ve literally made a living and a career by untangling big functions with early returns. I&#x27;ve really saved many situations and code just by doing that. The reason this happens is that early returns are gotos and gotos are harder to follow.<p>Also, you can&#x27;t move easily (think copy&#x2F;paste) code than has early returns, which means that the code is defacto harder to refactor. So in practice, code with early returns stays in place and grows.<p>Early returns are artefacts of the assembly jump instruction. They shouldn&#x27;t even be in a high-level programming language because it makes no sense to have jumps in such a language. They make the programmer lives in the assembly language world (succession of instructions that update a state) instead of the wonderful world of high-level programming (expressions).<p>If you interested by what I&#x27;m saying, you should try removing all returns, continues and breaks from your code, you&#x27;ll see what wonderful things happens. It&#x27;s literally magic. Things becomes so much more expressive without them. Which is the point, high level programming is about gaining more expressiveness over assembly code.<p>Early returns is one of the big pillars of bad inexpressive entangled convoluted programming. And what is people reason for using early returns? It makes less indentations...<p>You may wonder why early returns doesn&#x27;t sound that much like a big deal after all. And you are right, there is no big deal. No big deal in terms of what the market reward. Now if you care about the <i>art</i> of programming, this is a huge deal imo.<p><i>edit: thank you for the fair discussion. I would like to insist that obviously, if your code is more expressive, you will take better decisions and at the end, what I&#x27;m saying is that you will end up with a totally different program. Early return or not is not about cosmetic. It&#x27;s about writing better program.</i>