Sam Croft

Full-stack developer

Quick tip: return from functions as soon as possible

  • 0 comments

Filed in: best practices, coding, programming

Programming: always return as soon as possible

I wish I could recall where I first read about this programming approach, it’s something that has made my code much more readable over the last few years and I’d love to credit the author.

Avoid heavily indented/pointy code, return as soon as possible

The idea is simple; whenever you’re using conditional statements, always return (or throw an exception) as soon as possible to avoid complex nested if/else blocks.

(more…)