Too much code - slicing
usenet-nospam at seebs.net
Sun Sep 19 01:38:19 CEST 2010
On 2010-09-18, AK <andrei.avk at gmail.com> wrote:
> On 09/18/2010 06:56 PM, Seebs wrote:
>> Basically, I can handle
>> do x if y
>> pretty well, but
>> do x if y else z
>> always breaks my parser.
>> So in English, I might say "I'll go to the store if I have time", but
>> I'd rarely use "I'll go to the store if I have time, otherwise I'll send
>> the house elf"; instead, I'd say "If I have time, I'll go to the store,
>> otherwise I'll send the house elf."
> I actually find the shorter version slightly more readable than full
> version. I think in English you'd say it in one sentence and that to me
> feels like it should vaguely correspond to one line in code (perhaps
> split over more than one line but that'd be due to long var names or
> complex operations, not inherently).
I dunno, it always breaks my parser. The condition ends up between
the two dependents, and that doesn't work for me. I can have conditions
which are leading or trailing, but not infix.
> It's a bit more readable to me because I can tell at a glance that a
> single variable gets assigned a value based on a condition. With a
> longer version it looks like something more complicated it going on, and
> the eye has to look at all four lines and jump to another ident level.
Ahh! I see. There's several variants that could be discussed.
x = y
x = z
x = y if condition else z
And then the one I'm used to from other languages:
x = if condition then y else z
The other thing, from my point of view, is an ambiguity with a common
idiom I'm used to, again from other languages:
x = y if condition
If !condition, then nothing happens to x. So far as I can tell, that's
a syntax error in Python -- I can't use postfix if to modify a sentence,
because it's an expression thing.
> By the way, it also looks far more readable in an editor where if and
> else would be highlighted vs. all in plain colour.
I use syntax coloring in programming languages precisely as often, and
for precisely the same reasons, that I use it when writing in English.
Which is to say, if such a feature exists, I turn it off immediately
because it consistently distracts me from following the actual meaning
of code. Syntax is the least part of the meaning of code; giving extra
weight to syntax is pretty disruptive, IMHO.
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