Too much code - slicing
andrei.avk at gmail.com
Sun Sep 19 16:44:59 CEST 2010
On 09/19/2010 03:31 AM, Seebs wrote:
> On 2010-09-19, Steven D'Aprano<steve at REMOVE-THIS-cybersource.com.au> wrote:
>> Define "unbalanced".
> I'm not sure that's the word I'd use. I'm not even sure what it would mean
>> 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: ?--
> Just like:
> if condition:
> The condition is the primary, the clauses are secondary to it.
To me, the problem with C ternary is, why is true condition first and
false second? It could just as well be the other way around. With if and
else, the meaning is direct, x if y else z, or if y: x; else: z.
> It may be balanced, but it requires you to reevaluate what you're reading
> after you've already read something that seemed to have a clear meaning.
> Basically, think of what happens as I read each symbol:
> x = x + 1 if condition else x - 1
> Up through the '1', I have a perfectly ordinary assignment of a value.
> The, suddenly, it retroactively turns out that I have misunderstood
> everything I've been reading. I am actually reading a conditional, and
> the things I've been seeing which looked like they were definitely
> part of the flow of evaluation may in fact be completely skipped.
That's absolutely not how I read code. For example, if you have a line
x = x + 1 ASF!@#$!@$ASFASF!@#$!@$#ADFASDF!@#
Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is
I would read it like "there's something wrong at the end of line",
before I even see it as an assignment.
That's where syntax highlighting comes in, as well. What I see, at the
same time (i.e. not in sequence):
.. = .. if .. else ..
The second thing I see is what variable is being assigned to. Of couse,
this might change if I'm looking for that particular variable, then I
x = ................
> Consider the following lovely hypothetical syntax:
> if condition else:
> And there, at least you have some cue that you're about to see something
After some time getting used to it, I'd end up seeing this as:
if .. else:
at first and then processing everything else. Again, syntax highlighting
would help here. The only issue is that it'd be hard to separate the
beginning from other code, for me that'd be the primary reason why this
is not a good construct.
More information about the Python-list