Too much code - slicing
usenet-nospam at seebs.net
Sun Sep 19 23:32:29 CEST 2010
On 2010-09-19, AK <andrei.avk at gmail.com> wrote:
> Because that's what 'if' and 'else' mean.
My point is, I don't want the order of the clauses in if/else to change.
If it is sometimes "if <condition> <true-clause> else <false-clause>", then
it should *ALWAYS WITHOUT EXCEPTION* be condition first, then true clause,
then false clause. If it's sometimes "if condition true-clause else
false-clause", and sometimes "true-clause if condition else false-clause",
that's a source of extra complexity.
> I have no problem with '?'
> separating condition from possible outcomes.. The most natural reading
> of that construct is that depending on condition, there are two possible
> outcomes, separated by a ':' and you have to remember that first outcome
> corresponds to true condition.
Exactly as it ALWAYS does. That's the point.
> x = y if a else z is much more pythonic
> because 'else' is explicitly saying what happens on false condition.
> Explicit is better than implicit.
Is it "more pythonic" to shuffle the orders of clauses in precisely
I'm not arguing against the use of the *words* "if" and "else". I'm
arguing that the shuffling of the orders of the clauses creates
> It still has the advantage over the more verbose version that I
> mentioned before: you can see immediately that there's an assignment to
> a single variable, and the logic flows like a single sentence in a
> natural language.
I'm getting frustrated here because I really felt my point was pretty
clearly expressed, and yet, every time you respond, you respond to things
TOTALLY DIFFERENT from what I am saying.
The syntax I like for this kind of thing is:
x = if condition then true-clause else false-clause
This is because it follows the same *ordering* as the multi-line if/else,
so it preserves the logical flow. Condition, then true clause, then
false clause. Always.
The only way in which this is more verbose than the inverted one is the
"then", and you don't even need that if you stick with a python-style
x = if condition: true-clause else false-clause
But this is *always* easier to follow because it follows the same logical
Leave poetic inversion to the poets.
> That's not really true, it merely makes a given syntax easier to read
> even when it's already a preferable syntax.
Except that it's *NOT PREFERABLE* to me, because it is BACKWARDS.
Have I somehow failed to express this? Is there some magical rule that
it is not pythonic for you to react in any way to the actual comparison
I'm making, rather than to totally unrelated comparisons?
I gave the example of what an if/else statement looks like, not because
I think it is always better to use statements and blocks instead of
expressions, but to point out the LOGICAL ORDER. You were asking why
I preferred the condition to come first. My answer is, because the
condition comes first in an if/else statement normally, and I like to
preserve the logical flow. Instead, you're off ranting about how that's
But that's not my point. My point was *only* that the logical flow
is consistent between if/else and the way various languages have done
if/else expressions: Condition first, then true clause, then false
clause. Doesn't matter whether it's ruby or C or lua or even bourne
shell, in every other language I use that lets me use an if/else as
part of an expression, it follows the SAME logical flow as the regular
if/else statement. In Python, it's inverted.
You were arguing that this inversion is better and more intuitive,
and that there is no reason to expect the condition to come first.
But there is! The condition comes first in regular if/else statements.
This establishes a pattern -- if/else things are introduced by
their condition, then you get the true clause and then you get the
> Well, you're exaggerating this out of all proportion just to prove a
No, I'm not.
> This is a single construct I
> can think of, which, being already very readable, explicit, and
> succinct, *on top of that*, gains even more in readability due to syntax
But it's *not readable to me*. Because it's backwards.
> So, as you can see, I'd like syntax highlight just fine if this
> construct was not present in Python, and in fact I did. Conversely, I'd
> prefer it to the longer version if there was no syntax highlight at all.
And again, NO ONE HAS SUGGESTED THE LONGER VERSION. AT ALL. EVER. I
don't understand why you keep contrasting this with the longer version
when the only reason that was brought up was to COMPARE it in terms of
I pointed out the *PARALLELS* between conditional expressions and
conditional statements. I did not suggest that the longer version should
be preferred in all cases, or even in all that many.
> I'll concede you one point in this case: if the statement 'x = .. if ..
> else .. ' is split over two pages, I would at least seriously consider
> the 'if: .. else: ' version. ;)
Okay, one more time:
I am not proposing the use of multi-line statements as superior to
conditional expressions. I am *ONLY* stating that I find the
"true-clause if condition else false-clause" form confusing because it
inverts the LOGICAL FLOW of multi-line if/else statements.
By the nature of programming, I'm going to have to use if/else statements
a lot. So I'm going to be used to the way they flow -- condition,
true, false. Condition, true, false. Condition, true, false. It goes
in that order every time, in every language I use, both when working
with statements and when working with expressions. EXCEPT. That in
one specific language, when doing expressions (but not statements),
it is "True, condition, false."
That's all I'm talking about. I am not arguing whether conditional
expressions are better or worse than conditional statements. I am not
arguing whether conditional expressions should exist at all. I am
only pointing out that I find it much clearer when conditional expressions
follow the same pattern as other conditional things.
Condition, true, false.
Is there something horribly unusual about wanting to take advantage of
the fact that my brain has a much easier time processing things when they
follow consistent patterns?
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam at seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
More information about the Python-list