Re: "return" in def

2008-12-30 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : (snip) Avoiding early exits is an over-reaction to the Bad Old Days of spaghetti code. Mostly, yes. It can also be a way to help avoiding "resource leaks" (memory or whatever) - just like try/finally blocks or the 'with' statement in Python. But used wisely, earl

Re: "return" in def

2008-12-29 Thread Aaron Brady
On Dec 29, 7:00 pm, Steven D'Aprano wrote: > On Mon, 29 Dec 2008 05:31:17 -0800, Aaron Brady wrote: > > 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. > > That's silly. You tr

Re: "return" in def

2008-12-29 Thread Steven D'Aprano
On Mon, 29 Dec 2008 05:31:17 -0800, Aaron Brady wrote: > 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. That's silly. You treat the function as a black box: input comes in, and

Re: "return" in def

2008-12-29 Thread Aaron Brady
On Dec 28, 11:56 am, Gerard Flanagan wrote: > On Dec 28, 5:19 pm, Roger 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 > >         retur

Re: "return" in def

2008-12-29 Thread Bruno Desthuilliers
John Machin a écrit : On Dec 29, 8:26 pm, Bruno Desthuilliers wrote: John Machin a écrit : (snip) Please don't. Follow MRAB's advice, with the corollary that a generator is forced by the compiler to be a "procedure" in MRAB's terminology. I fail to see any *practical* difference between MRAB

Re: "return" in def

2008-12-29 Thread John Machin
On Dec 29, 8:26 pm, Bruno Desthuilliers wrote: > John Machin a écrit : > > > > > On Dec 29, 7:06 am, Roger wrote: > >>> Curious. When I see a bare return, the first thing I think is that the > >>> author forgot to include the return value and that it's a bug. > >>> The second thing I think is tha

Re: "return" in def

2008-12-29 Thread Bruno Desthuilliers
John Machin a écrit : On Dec 29, 7:06 am, Roger wrote: Curious. When I see a bare return, the first thing I think is that the author forgot to include the return value and that it's a bug. The second thing I think is that maybe the function is a generator, and so I look for a yield. If I don't

Re: "return" in def

2008-12-28 Thread Roger
On Dec 28, 5:12 pm, John Machin wrote: > On Dec 29, 7:06 am, Roger wrote: > > > > > > Curious. When I see a bare return, the first thing I think is that the > > > author forgot to include the return value and that it's a bug. > > > > The second thing I think is that maybe the function is a genera

Re: "return" in def

2008-12-28 Thread John Machin
On Dec 29, 7:06 am, Roger wrote: > > Curious. When I see a bare return, the first thing I think is that the > > author forgot to include the return value and that it's a bug. > > > The second thing I think is that maybe the function is a generator, and > > so I look for a yield. If I don't see a y

Re: "return" in def

2008-12-28 Thread John Machin
On Dec 29, 8:36 am, Benjamin wrote: > On Dec 28, 1:35 pm, Steven D'Aprano > cybersource.com.au> wrote: > > The second thing I think is that maybe the function is a generator, and > > so I look for a yield. > > You shouldn't, though; Generators can't contain any return statement. What gave you th

Re: "return" in def

2008-12-28 Thread Robert Kern
Benjamin wrote: On Dec 28, 1:35 pm, Steven D'Aprano wrote: The second thing I think is that maybe the function is a generator, and so I look for a yield. You shouldn't, though; Generators can't contain any return statement. Yes, they can. It doesn't return a value, it just raises a StopIter

Re: "return" in def

2008-12-28 Thread Benjamin
On Dec 28, 1:35 pm, Steven D'Aprano wrote: > The second thing I think is that maybe the function is a generator, and > so I look for a yield. You shouldn't, though; Generators can't contain any return statement. -- http://mail.python.org/mailman/listinfo/python-list

Re: "return" in def

2008-12-28 Thread Roger
> Curious. When I see a bare return, the first thing I think is that the > author forgot to include the return value and that it's a bug. > > The second thing I think is that maybe the function is a generator, and > so I look for a yield. If I don't see a yield, I go back to thinking > they've left

Re: "return" in def

2008-12-28 Thread Steven D'Aprano
On Sun, 28 Dec 2008 12:38:50 -0500, Steve Holden wrote: > Roger wrote: >> Hi Everyone, >> >> First I want to thank everyone that posts to this group. I read it >> daily and always learn something new even if I never feel like I have >> anything to contribute but my questions. >> >> When I defin

Re: "return" in def

2008-12-28 Thread MRAB
Gerard Flanagan wrote: On Dec 28, 5:19 pm, Roger 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 un

Re: "return" in def

2008-12-28 Thread Manish Sinha
Roger wrote: Hi Everyone, First I want to thank everyone that posts to this group. I read it daily and always learn something new even if I never feel like I have anything to contribute but my questions. Same here, I always read the news, but hardly post anything since am not very much expe

Re: "return" in def

2008-12-28 Thread Bruno Desthuilliers
Roger a écrit : 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? If it's the last statement in the function body, it is indeed "excessive

Re: "return" in def

2008-12-28 Thread Gerard Flanagan
On Dec 28, 5:19 pm, Roger 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 af

Re: "return" in def

2008-12-28 Thread Steve Holden
Roger wrote: > Hi Everyone, > > First I want to thank everyone that posts to this group. I read it > daily and always learn something new even if I never feel like I have > anything to contribute but my questions. > > When I define a method I always include a return statement out of > habit even

Re: "return" in def

2008-12-28 Thread r
On Dec 28, 11:19 am, Roger wrote: > Hi Everyone, > > First I want to thank everyone that posts to this group.  I read it > daily and always learn something new even if I never feel like I have > anything to contribute but my questions. > > When I define a method I always include a return statement

"return" in def

2008-12-28 Thread Roger
Hi Everyone, First I want to thank everyone that posts to this group. I read it daily and always learn something new even if I never feel like I have anything to contribute but my questions. When I define a method I always include a return statement out of habit even if I don't return anything e