Re: [Python-Dev] PEP 8 update

2015-04-07 Thread Steven D'Aprano
On Tue, Apr 07, 2015 at 08:47:25AM -0400, Ben Hoyt wrote: > > My own preference would be: > > > > def foo(x): > > if x >= 0: > > return math.sqrt(x) > > return None > > Kind of getting into the weeds here, but I would always invert this to > "return errors early, an

Re: [Python-Dev] PEP 8 update

2015-04-07 Thread Guido van Rossum
Talk about hijacking an unrelated thread... :-( Though there's maybe a style rule for the ternary operator to be devised here? :-) On Apr 7, 2015 11:36 AM, "Stefan Behnel" wrote: > Antoine Pitrou schrieb am 07.04.2015 um 14:26: > > On Tue, 07 Apr 2015 03:11:30 +0100 > > Rob Cliffe wrote: > >>

Re: [Python-Dev] PEP 8 update

2015-04-07 Thread Stefan Behnel
Antoine Pitrou schrieb am 07.04.2015 um 14:26: > On Tue, 07 Apr 2015 03:11:30 +0100 > Rob Cliffe wrote: >> >> On 07/04/2015 02:08, Guido van Rossum wrote: >>> I've taken the liberty of adding the following old but good rule to >>> PEP 8 (I was surprised to find it wasn't already there since I've

Re: [Python-Dev] PEP 8 update

2015-04-07 Thread Ben Hoyt
> My own preference would be: > > def foo(x): > if x >= 0: > return math.sqrt(x) > return None Kind of getting into the weeds here, but I would always invert this to "return errors early, and keep the normal flow at the main indentation level". Depends a little on w

Re: [Python-Dev] PEP 8 update

2015-04-07 Thread Antoine Pitrou
On Tue, 07 Apr 2015 03:11:30 +0100 Rob Cliffe wrote: > > On 07/04/2015 02:08, Guido van Rossum wrote: > > I've taken the liberty of adding the following old but good rule to > > PEP 8 (I was surprised to find it wasn't already there since I've > > lived by this for ages): > > > > * > > > >

Re: [Python-Dev] PEP 8 update

2015-04-06 Thread Steven D'Aprano
On Tue, Apr 07, 2015 at 03:11:30AM +0100, Rob Cliffe wrote: > As a matter of interest, how far away from mainstream am I in > preferring, *in this particular example* (obviously it might be > different for more complicated computation), > > def foo(x): > return math.sqrt(x) if x >=

Re: [Python-Dev] PEP 8 update

2015-04-06 Thread Rob Cliffe
On 07/04/2015 02:08, Guido van Rossum wrote: I've taken the liberty of adding the following old but good rule to PEP 8 (I was surprised to find it wasn't already there since I've lived by this for ages): * Be consistent in return statements. Either all return statements in a functi

Re: [Python-Dev] PEP 8 update

2015-04-06 Thread Barry Warsaw
On Apr 06, 2015, at 06:08 PM, Guido van Rossum wrote: >I've taken the liberty of adding the following old but good rule to PEP 8 >(I was surprised to find it wasn't already there since I've lived by this >for ages): > > Be consistent in return statements. Either all return statements in a > fu

[Python-Dev] PEP 8 update

2015-04-06 Thread Guido van Rossum
I've taken the liberty of adding the following old but good rule to PEP 8 (I was surprised to find it wasn't already there since I've lived by this for ages): - Be consistent in return statements. Either all return statements in a function should return an expression, or none of them sh