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

Larry Bates lbates at syscononline.com
Wed Nov 17 11:12:39 EST 2004


I think what you want is :

def analysis(self, morf):
     filename, statements = self.analyze_morf(morf)
     missing = []
     for line in statements:
         if not self.cexecuted[filename].has_key(line):
             missing.append(line)

     return (filename, statements, missing,
             self.format_lines(statements, missing))

There is complete symmetry.  You can return as many
"things" as you want.  All Jeremy is saying is
that it the tuple/list of things gets complex, you
should probably refactor your code and make the
"things" into a class with the return values as
attributes.

Larry Bates



Robert Brewer wrote:
> 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.
>>
>>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.
> 
> 
> Hm. I'd guess it has more to do with arguments at all. That is, a
> function has an input argument list which is metadata with respect to
> the function body. There's no such "output argument list", at least not
> specified in code. That's the fundamental asymmetry. Maybe we should
> support:
> 
> def analysis(self, morf):
>     filename, statements = self.analyze_morf(morf)
>     missing = []
>     for line in statements:
>         if not self.cexecuted[filename].has_key(line):
>             missing.append(line)
> end analysis(filename, statements, missing,
>              self.format_lines(statements, missing))
> 
> 
> /ducking and running ;)
> 
> 
> Robert Brewer
> MIS
> Amor Ministries
> fumanchu at amor.org



More information about the Python-list mailing list