Concrete Proposal: while ... and while ...
Corran Webster
cwebster at math.tamu.edu
Wed May 19 23:35:20 EDT 1999
In article <927132579snz at vision25.demon.co.uk>,
Phil Hunt <philh at vision25.demon.co.uk> wrote:
>In article <7hsv80$g9j$1 at news.tamu.edu>
> cwebster at math.tamu.edu "Corran Webster" writes:
>
>If this is added to the language, it will make programs harder to read.
>
>With your notation the ``and while ...'' line goes at the same level of
>indentation as the original ``while'' line; this makes it look as if it
>is ending that block and starting another one.
This is part of the point - it _is_ starting a new block. I don't see
it as making things any harder to read than "if .. elif ... else" or
even the existing "while ... else ..." constructions. I will agree
with you that it could be more readable, but I think this is the best
that can be done while not adding a new keyword.
>Perhaps it would be better to have the ``and while ...'' line indented
>inside the while loop?
I think that would be very unnatural for python - it would make "and while"
a statement in it's own right and open a whole new can of worms. What
happens if it's used outside a while loop? What happens if there's two
or more of them? That would change this from a minor tweak to introducing
a whole new construct into the language. I doubt Guido would go for it,
and I'd agree with him.
But by all means code something up and see how it works.
>Or better still, just use ``if not test: break''.
Which you still can under this proposal.
>> The "while 1" idiom is about the only thing which
>> irks me about the language, and it's something I'd like to see changed.
>> Compared to how smooth the rest of the language is, it sticks out like a
>> sore thumb. I'd prefer to see it spelt "do: ... while test: ..." but
>> understand the reluctance to add new keywords.
>
>IMO allowing ``while:'', meaning ``while 1:'' is a reasonable shortcut.
I'd agree with you here, but to allow it by itself would have added
another level of complexity to the patch. But it's not so much the "1"
in there which irks me so much as the whole convoluted construct. I'd
much rather have something cleaner available.
scratching-an-itch-ly y'rs,
Corran
More information about the Python-list
mailing list