Re: Coding style and else statements

2006-08-31 Thread Ben Finney
[EMAIL PROTECTED] writes: > > To my eyes, that's less readable than, and has no benefit over, > > the following: > > > > def foo(thing): > > if thing: > > result = thing+1 > > else: > > result = -1 > > return result I chose this to more clearly

Re: Coding style and else statements

2006-08-31 Thread matt . newville
> To my eyes, that's less readable than, and has no benefit over, the > following: > > def foo(thing): > if thing: > result = thing+1 > else: > result = -1 > return result I wouldn't discount: def foo(thing): result = -1 if thing:

Re: Coding style and else statements

2006-08-31 Thread Ben Finney
Pete Forman <[EMAIL PROTECTED]> writes: > Ben Finney <[EMAIL PROTECTED]> writes: > > > Why not ensure that there is one return point from the function, > > so the reader doesn't have to remind themselves to look for hidden > > return points? > > There will always be more potential return points in

Re: Coding style and else statements

2006-08-31 Thread Pete Forman
Ben Finney <[EMAIL PROTECTED]> writes: > Why not ensure that there is one return point from the function, so > the reader doesn't have to remind themselves to look for hidden > return points? There will always be more potential return points in languages that support exceptions. -- Pete Forma

Re: Coding style and else statements

2006-08-30 Thread Ben Finney
"Carl Banks" <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > > "Carl Banks" <[EMAIL PROTECTED]> writes: > > > def foo(thing): > > > if thing: > > > return thing+1 > > > else: > > > return -1 > > > assert False > > > > To my eyes, that's less readable than, and has no

Re: Coding style and else statements

2006-08-30 Thread Carl Banks
Steve Holden wrote: > Carl Banks wrote: > [...] > > However, I have rare cases where I do choose to use the else (ususally > > in the midst of a complicated piece of logic, where it's be more > > distracting than concise). In that case, I'd do something like this: > > > > def foo(thing): > >

Re: Coding style and else statements

2006-08-30 Thread Carl Banks
Ben Finney wrote: > "Carl Banks" <[EMAIL PROTECTED]> writes: > > > However, I have rare cases where I do choose to use the else > > (ususally in the midst of a complicated piece of logic, where it's > > be more distracting than concise). In that case, I'd do something > > like this: > > > > def f

Re: Coding style and else statements

2006-08-30 Thread [EMAIL PROTECTED]
Tal Einat wrote: > I meant to say that: > > (thing and [thing+1] or [-1])[0] > > is more readable (IMO) than: > > thing != -1 and (thing and thing+1 or -1) or 0 Neither is particularly readable, though I agree that the latter is worse since it has to have the third option ("0") on the end. But I'

Re: Coding style and else statements

2006-08-30 Thread Gabriel Genellina
At Wednesday 30/8/2006 04:47, Tal Einat wrote: I meant to say that: (thing and [thing+1] or [-1])[0] is more readable (IMO) than: thing != -1 and (thing and thing+1 or -1) or 0 Interesting to find how different persons feel "readability" - for me, the later is rather clear (but definitivel

Re: Coding style and else statements

2006-08-30 Thread Tal Einat
Sybren Stuvel wrote: > Tal Einat enlightened us with: > > Actually, the common work-around for this is: > > > > (thing and [thing+1] or [-1])[0] > > > > This works since non-empty lists are always considered true in > > conditional context. This is more generic, and IMO more readable. > > I think

Re: Coding style and else statements

2006-08-30 Thread Ben Finney
"Carl Banks" <[EMAIL PROTECTED]> writes: > However, I have rare cases where I do choose to use the else > (ususally in the midst of a complicated piece of logic, where it's > be more distracting than concise). In that case, I'd do something > like this: > > def foo(thing): > if thing: >

Re: Coding style and else statements

2006-08-29 Thread Steve Holden
Carl Banks wrote: [...] > However, I have rare cases where I do choose to use the else (ususally > in the midst of a complicated piece of logic, where it's be more > distracting than concise). In that case, I'd do something like this: > > def foo(thing): > if thing: > return thing+1 >

Re: Coding style and else statements

2006-08-29 Thread Carl Banks
tobiah wrote: > def foo(thing): > if thing: > return thing + 1 > else: > return -1 > > def foo(thing): > if thing: > return thing + 1 > return -1 > > Obviously both do the same thing. The first is > possibly clearer, while the secon

Re: Coding style and else statements

2006-08-29 Thread Tal Einat
Bruno Desthuilliers wrote: > Sam Pointon a écrit : > > Bruno Desthuilliers wrote: > > > >>foo = lambda thing: thing and thing + 1 or -1 > > > > > > The and ... or trick is buggy (what if thing == -1?) > > Yes, true - Should be: > foo2 = lambda t: t != -1 and (t and t+1 or -1) or 0 > Actually, the

Re: Coding style and else statements

2006-08-28 Thread Bruno Desthuilliers
Sam Pointon a écrit : > Bruno Desthuilliers wrote: > >>foo = lambda thing: thing and thing + 1 or -1 > > > The and ... or trick is buggy (what if thing == -1?) Yes, true - Should be: foo2 = lambda t: t != -1 and (t and t+1 or -1) or 0 > and bad style. Lol. Well, so what about: foo = lambda

Re: Coding style and else statements

2006-08-28 Thread Tal Einat
tobiah wrote: > def foo(thing): > > if thing: > return thing + 1 > else: > return -1 > > def foo(thing): > > if thing: > return thing + 1 > return -1 > > Obviously both do the same thing. The first is > possibly clearer, while the s

Re: Coding style and else statements

2006-08-28 Thread Sam Pointon
Bruno Desthuilliers wrote: > foo = lambda thing: thing and thing + 1 or -1 The and ... or trick is buggy (what if thing == -1?) and bad style. If you -do- want a conditional expression, 2.5 provides one: thing + 1 if thing else -1 No subtle logical bugs, and a good deal more obvious. On the top

Re: Coding style and else statements

2006-08-28 Thread Bruno Desthuilliers
tobiah a écrit : > def foo(thing): > > if thing: > return thing + 1 > else: > return -1 > > def foo(thing): > > if thing: > return thing + 1 > return -1 > > Obviously both do the same thing. The first is > possibly clearer, while the second is more conci

Re: Coding style and else statements

2006-08-28 Thread Jorge Vargas
On 8/28/06, tobiah <[EMAIL PROTECTED]> wrote: > def foo(thing): > > if thing: > return thing + 1 > else: > return -1 > > def foo(thing): > > if thing: > return thing + 1 > return -1 > > Obviously both do the same thing.

Coding style and else statements

2006-08-28 Thread tobiah
def foo(thing): if thing: return thing + 1 else: return -1 def foo(thing): if thing: return thing + 1 return -1 Obviously both do the same thing. The first is possibly clearer, while the second is more concise. Co