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

John Roth newsgroups at jhrothjr.com
Wed Nov 17 12:36:45 EST 2004


Since I seem to have missed the start of this thread,
I'm going to reply at a higher level...

"Robert Brewer" <fumanchu at amor.org> wrote in message 
news:mailman.6468.1100667418.5135.python-list at python.org...
Greg Ewing wrote:
> 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.

Well, there's a community of opinion in the stricter
parts of the OO world that _all_ return values should
be wrapped up in a class; you should never return
fundamental values (except possibly True and False.)

I know for myself that even if I intend to consume
multiple values immediately, the operation of unpacking
a tuple or remembering the index of the particular operand
I want is rather error-prone.

Another consideration is that there's a semantic
gap between a tuple and an object: while you can
regard a tuple as a data object, as soon as you want
to expand it to have some behavior, you've got to
make lots of changes everywhere that tuple is
used, or else put in lots of mechanism to make the
new object look like a tuple to the old users.

All of that is balanced, of course, by having to
create an object definition with a bunch of accessors.

I know that if I was working on a significant
project for someone else, I'd strongly consider
return objects everywhere, if only for the
documentation effect.

John Roth




More information about the Python-list mailing list