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

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Nov 16 22:49:03 EST 2004


Jeremy Bowers wrote:
> Generally, returning a tuple is either a sign that your return value
> should be wrapped up in a class, or the function is doing too much.

While I suspect you may be largely right, I
find myself wondering why this should be so. We
don't seem to have any trouble with multiple inputs
to a function, so why should multiple outputs be
a bad thing? What is the reason for this asymmetry?

Perhaps it has something to do with positional vs.
keyword arguments. If a function has too many input
arguments to remember what order they go in, we
always have the option of specifying them by
keyword. But we can't do that with the return-a-tuple-
and-unpack technique for output arguments -- it's
strictly positional.

Maybe things would be better if we had "dict unpacking":

   a, c, b = {'a': 1, 'b': 2, 'c': 3}

would give a == 1, c == 3, b == 2. Then we could
accept outputs by keyword as well as inputs...

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list