Style question for conditional execution

Steven Howe howe.steven at
Wed Nov 24 20:40:41 CET 2010

Both paradigms are in the bash shell. Using a test switch (like -x for 
executiable) mixed with an && or ||.
	[-x /usr/bin/firefox ] || exit

I think it's very clear, to old hands, but not so much for a new or
intermediate users.

It certainly is the 'cleaner' form. Like the C style increment " x++ " 
or the insidious  " x += 4 ". However I often found myself looking for 
places to use "x += 4" instead of just using the clear:
	"x = x + 4 ".

Unless there is a significant compiler/executable improvement it just 
there to amuse yourself.

	if v:

structure is clearer. Which is the only reason to use indents, braces 
and the like. I suppose that's my vote/opinion. Given a choice between 
clean or clear, take clear.


On 11/24/2010 10:46 AM, Gerald Britton wrote:
> Writing in Python gives me the luxury of choosing different paradigms
> for similar operations.  Lately I've been thinking about a minor
> detail that peaked my interest and am curious what others think:
> Say that I have some function "f" that I will execute if some variable
> "v" evaluates true.  Using a classical procedural approach, I might
> write:
>      if v:
>          f()
> I might, however, think more in a functional-programming direction.
> Then I might write:
>      v and f()
> Interestingly, this second expression compiles smaller (though only by
> a little) in both Python 2.6 and 3.1, which I currently have
> installed.  If I had thousands of such expressions, I could boast
> about a measurable difference but practically speaking, it is not
> significant.
> What I _am_ interested in, however, is feedback from a style perspective.
> What do the rest of you think about this?
> Have you used the second approach and, if so, what was your motivation?
> Is there a good/bad reason to choose one over the other?

More information about the Python-list mailing list