Page 1 of 1

Write RETURN in the end of subroutines, returning nothing

PostPosted: 21 Feb 2013, 15:34
by Ursego
Always end subroutines, returning nothing (like procedures in PL/SQL or void methods in C#) with return instruction.

Compilers don't force us to write return as the last statement of subroutines which return nothing, but it can be pretty useful in debugging if the last executable construction of the function enables program flow to go inside it or to jump over it (for example, if the script's LAST construction is an if, switch or a loop). If that construction is skipped by the program flow (let's say, doesn't go inside an if) then the debugger's cursor will stop on the discussed return, so you have a chance to do something before the method has been exited. Don't analyze if the final return can be useful or not, simply write it in the end of EACH subroutine - that will never do any harm. It was a requirement in one of companies I has worked for!