¿Un return o varios?

La cosa no está clara:

https://stackoverflow.com/questions/36707/should-a-function-have-only-one-return-statement

Artículo sobre el tema:

https://www.anthonysteele.co.uk/TheSingleReturnLaw

Una buena práctica:

Minimize the number of returns in each routine. It’s harder to understand a routine if, reading it at the bottom, you’re unaware of the possibility that it returned somewhere above.

Use a return when it enhances readability. In certain routines, once you know the answer, you want to return it to the calling routine immediately. If the routine is defined in such a way that it doesn’t require any cleanup, not returning immediately means that you have to write more code.

Publicado por

Juan Pablo Fuentes

Formador de programación y bases de datos