Too much code - slicing
andrei.avk at gmail.com
Sun Sep 19 02:00:32 CEST 2010
On 09/18/2010 07:38 PM, Seebs wrote:
> 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.
> if condition:
> 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.
Funny that you should say that, because I thought quite a few times that
it would be really awesome if some texts in English had syntax
highlighting. Obviously, not Brothers Karamazov, but something like a
tutorial, or a manual, or an online article. If key words were
highlighted, I'd be able to quickly glance over parts that are not
useful to me at the time, and find the interesting bits.
For instance, in the above paragraph I'd highlight 'awesome', 'English',
'syntax highlighting', 'tutorial', 'manual', 'online article',
'quickly glance over', 'not useful', 'find', 'interesting bits'.
It'd be like speed reading, except real!
More information about the Python-list