stylistic question -- optional return value
sschwarzer at sschwarzer.net
Wed Aug 28 22:12:27 CEST 2002
Andrew Koenig wrote:
> Hans> Still, I believe that rewriting the function (or splitting it up)
> Hans> might be a better idea. <0.3 wink>
> I've considered that, and I really don't think it works in this case.
A variant of returning a tuple but with more readability could be:
# you may use another name
result = ValueWithDebugInfo()
result.that_what_i_want = ...
result.debug_info = ...
> You might think of the optional result as being similar to debugging
> information -- you really don't want to put the code that getnerates
> debugging information into a separate function, because then it will
> surely diverge from the code about which it is providing the information.
If you need it for debugging I rather recommend other approaches. How about
self._debug_log = 
x = X()
y = x.do_something()
print x._debug_log # what has happened?
More information about the Python-list