Are multiple return values really harmful? (Re: determining the number of output arguments)

Bengt Richter bokr at oz.net
Thu Nov 18 22:34:59 EST 2004


On Thu, 18 Nov 2004 08:56:30 +0100, aleaxit at yahoo.com (Alex Martelli) wrote:

>Bengt Richter <bokr at oz.net> wrote:
>   ...
[...]
>
>> Still, as Carlos pointed out, formal parameter names
>> are private to a function,
(If I misunderstood and misrepresented what Carlos wrote, I apologize)
>
>? No they're not -- a caller knows them, in order to be able to call
>with named argument syntax.
>
I guess you mean keyword arguments, so yes, but for other args I would argue that the caller's
knowledge of formal parameter names really only serves mnemonic purposes.
I.e., once the calling code is written, e.g. an obfuscated-symbols
version of the function may be substituted with no change in program
behavior. So in that sense, there is no coupling: the writer of the
calling code is not forced to use any of the function's internal names
in _his_ source code. This is in contrast with e.g. a returned dict or
name-enhanced tuple: he _is_ forced to use the given actual names in _his_ code,
much like keyword arguments again.

That, incidentally, is why Carlos' decorator suggestion looked good to me. I.e.,
if it could be used to wrap an outside function that returns a plain tuple,
the choice of names would be back in the caller's source code again. Let' see if I can find
it to quote ... not far away...

"""
@returns('year','month','day')
def today():
    ...
    return year, month, day
"""
Applying that (ignoring optimization ;-) to an outside function:

@returns('year','month','day')
def today(*args,**kw):
    return outside_function(*args, **kw)

which my some magic would create a today function than returned
a named tuple, with names chosen by the call coder.

Regards,
Bengt Richter



More information about the Python-list mailing list