On Thursday, November 1, 2012 2:59:22 PM UTC-6, minux wrote:
One drawback for bare return statements, the it's hard to find out the actual value returned for
each return value. You effectively have to follow all paths of execution to be sure of which value
is returned.
I disagree with that notion altogether. You're implying that explicit return values using variables don't require you to trace all (or at least the pertinent) paths of execution to find out what the returned _values_ will be. Only returning constants (e.g. `return 5, nil`) don't require you to trace paths of execution for this purpose.
Bare return values corresponding to named return variables have the following characteristics:
* Can look in one place (the func signature) to find the _names_ of the expected return variables.
* Must trace pertinent paths of execution to determine the returned values.
* When tracing, must be aware of shadowed names, e.g. using short decls, which may lead to the expected _shadowing_ vars not being used when returning.
* A faster trace of the value(s) can work from outer scopes to inner scopes (if and when a variable is shadowed, tracing can stop before that inner-scope boundary).
Explicit _variable_ return values have the following characteristics:
* Can look in one place (the return statement) to find the _names_ of the expected return variables.
* Must trace pertinent paths of execution to determine the returned values.
* When tracing, must be aware of shadowed names in inner scopes, which may lead to the _shadowed_ variables not being modified as expected.
* A quick determination of the variable(s) used in the return can work from inner scopes to outer scopes (if and when a variable is shadowed, tracing can stop before that outer-scope boundary).
In both scenarios, the complexity involved in fully understanding the execution is the same -- explicit returns have the opposite (but no more simple) nature to bare returns in some cases, and the same characteristics in others.