Re: "return" in def



On Dec 28, 11:56 am, Gerard Flanagan <grflana...@xxxxxxxxx> wrote:
On Dec 28, 5:19 pm, Roger <rdcol...@xxxxxxxxx> wrote:

Hi Everyone,
[...]
When I define a method I always include a return statement out of
habit even if I don't return anything explicitly:

def something():
        # do something
        return

Is this pythonic or excessive?  Is this an unnecessary affectation
that only adds clock ticks to my app and would I be better off
removing "returns" where nothing is returned or is it common practice
to have returns.

It's not particularly excessive but it is uncommon. A nekkid return
can sometimes be essential within a function body, so a non-essential
nekkid return could be considered just noise.

One style of coding I heard about once only permits returns at the end
of a function. It claims it makes it easier to see the function as a
mathematical object.

It's a slick idea, but multiple exit points are really practical.

Incidentally, generators have multiple entry points. They "yield
multiple times, they have more than one entry point and their
execution can be suspended" -- http://docs.python.org/reference/expressions..html#yield-expressions

The discussion makes me think that 'clear' is subjective, just like
'natural' has 39 definitions.
.



Relevant Pages

  • Re: Python style guidelines
    ... >>one point it was recognized that multiple entry points into a ... >>to multiple exit points. ... Parameters can validated, resources ... > and then doesn't find all the subsequent exit points. ...
    (comp.lang.python)
  • Re: Detecting the active CDocument in an application?
    ... It is common practice. ... as the source code view, the graph view, the live-device view, etc. ... Is there an easy way to get a handle to the rich edit control and avoid ... Since a document can have multiple views, unless the view you want is ...
    (microsoft.public.vc.mfc)
  • Re: he sung
    ... "Multiple Caucasian females were observed to be proceeding in the ... Genetics i. 21 It has been a common practice ... having sustained multiple injuries in a fall.> ...
    (alt.usage.english)
  • Re: How to develop a random number generation device
    ... John Larkin writes: ... C doesn't encourage subroutines that have multiple entry and multiple ... Multiple exit points are no problem - you can easily ... Multiple entry points to a *function* are a bit more awkward - but you ...
    (sci.electronics.design)

Loading