This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Geza
Recipients Geza
Date 2011-02-11.18:31:21
SpamBayes Score 6.7863493e-12
Marked as misclassified No
Message-id <1297449083.34.0.083242555251.issue11196@psf.upfronthosting.co.za>
In-reply-to
Content
It would be nice if you could write a function like this (besides, of course, the current way):

def result=functionname(params):
  ...
  result=something

It would suffice for most functions, since you usually always return one type of value, and it can be very convenient in certain cases.
This is the way it is done e.g. in Matlab.

Advantages: 
- You can easily see what the function returns (e.g. by writing a tuple as the return value), without having to read the function body, or without hoping to find it in the comments.
- You can initialize the return values, and then care about the cases where they change.
- If you change the setup of the return value (e.g. insert a new item into the tuple), you do not need to change the "return" statement at possibly several places in the function body.

Disadvantages:
- I suggest it as an addition, so there isn't really. One person may decide to use one way, one the other.
- Of course, if you mix using the two ways, you may need to look at the function header to see which one you used.

Some more details to the idea:
- The return values are initialized to None.
- You can use the "return" statement just as before, but without arguments, to return from anywhere in the code.
- If you specify arguments to the "return" statement, Python stops with an exception.

The idea at this stage of Python development may be surprising, but I hope that nevertheless you will consider the idea seriously.

Thanks, and best regard!
History
Date User Action Args
2011-02-11 18:31:23Gezasetrecipients: + Geza
2011-02-11 18:31:23Gezasetmessageid: <1297449083.34.0.083242555251.issue11196@psf.upfronthosting.co.za>
2011-02-11 18:31:22Gezalinkissue11196 messages
2011-02-11 18:31:21Gezacreate