Python indentation

Antoon Pardon apardon at forel.vub.ac.be
Tue Jul 13 09:10:06 CEST 2004


Op 2004-07-12, Mark 'Kamikaze' Hughes schreef <kamikaze at kuoi.asui.uidaho.edu>:
> Antoon Pardon <apardon at forel.vub.ac.be>
> wrote on 12 Jul 2004 11:19:50 GMT:
>> Op 2004-07-09, Mark 'Kamikaze' Hughes schreef <kamikaze at kuoi.asui.uidaho.edu>:
>>>   This confuses me as to where the loop starts and ends:
>> This confusion may be nothing more than your unfamiliary which
>> such a construct.
>>> linenum=1
>>> while True:
>>>     line = raw_input()
>>> and while line:
>>>     print "%05d:%s" % (linenum, line,)
>>>     linenum += 1
>
>   No, I am quite certain that my confusion is due to the block
> indentation aimlessly wandering out, then in, then out again, then in at
> the end.  And I'm supposed to visually identify that as a single flow of
> execution?  Bugger that.

It is as much a single flow of execution as an if elif else.

>   I've programmed in dozens of languages.  None but BASIC and various
> assembly languages have a loop structure quite so ugly as that.

What I don't care about uglyness. I care about implementing algorithms.
If an algorithm is best expressed in such a kind of loop I prefer to
implement in such a kind of loop.
>
>>>   I rarely use post-loop condition testing even in Java where it exists
>>> and you can use assignment as an expression, let alone in Python.  When
>>> I do, an explicit if...break at the end works fine.
>> That is not an argument.
>
>   Actually, it is.  You just didn't follow it.  Python does not have
> assignment as expressions, which is a feature that makes post-loop
> testing more convenient.  Python does have a practical solution to that
> kind of loop already.

IMO it is as practical as combining an if with a goto.

>   Python wins now because it is simple, and clear, and there's one
> explicitly correct way to solve most tasks.

No there is not.

>> Before instructions like while, repeat etc
>> existed, we could use the equivallent of an if combined with a goto
>> and that worked fine too.
>
>   Ah, so your plan is to return to those golden times with equally
> incoherent block structures.

There is nothing incoherent about the proposed structure. A break
or continue in the middle of a loop is more like a goto and less
structured than a loop with multiple exit conditions.

The specific proposed syntax may be ugly, but that doesn't
make the structure incoherent.

-- 
Antoon Pardon



More information about the Python-list mailing list