Too much code - slicing

AK andrei.avk at gmail.com
Sun Sep 19 10:44:59 EDT 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
> here.
>
>> 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: ?--
>
> Yes.
>
> Just like:
> 	if condition:
> 	    foo
> 	else:
> 	    bar
>
> 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
like:

  x = x + 1 ASF!@#$!@$ASFASF!@#$!@$#ADFASDF!@#

Do you read it as "ok, assignment.. x is x + 1.. whoa, what the hell is
this?".

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
might see:

x ................

or

x = ................


>
>
> Consider the following lovely hypothetical syntax:
>
> 		foo
> 		bar
> 		baz
> 	if condition else:
> 		blah
> 		blah
> 		blah
>
> And there, at least you have some cue that you're about to see something
> happen.

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.

  -ak



More information about the Python-list mailing list