Too much code - slicing

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Sep 18 23:20:38 EDT 2010


On Sat, 18 Sep 2010 19:09:33 -0700, Carl Banks wrote:

> Apart from occasions like this and throwaway one-liners I use regular
> if-then statements.  If Python had added the C-like a ? b : c, then I'd
> use it a lot more, since that version is not inherently unbalanced.

Define "unbalanced".

Putting aside the over-use of punctuation, The C syntax feels unbalanced 
to me. You have:

condition IF true-clause ELSE false-clause

so both clauses follow the test, that is, they're on the same side: ?--

This looks unbalanced to me. And it reads like something Yoda would say, 
or Forth code.

But the Python syntax looks balanced to me:

true-clause IF condition ELSE false-clause

which is not only plain English, but perfectly balanced, with a clause on 
either side of the test: -?-

Python's ternary-if puts the emphasis on the true-clause, while C's 
ternary-if puts the emphasis on the test. I'm not convinced that this is 
necessarily a better choice than Python's. It's a *valid* choice, but 
better? I don't think so, but I accept that at least partially boils down 
to subjective factors.



-- 
Steven



More information about the Python-list mailing list