Concrete Proposal: while ... and while ...

Michael P. Reilly arcege at shore.net
Thu May 20 14:19:38 EDT 1999


Corran Webster <cwebster at math.tamu.edu> wrote:
: In article <y0j675pmg6c.fsf at vier.idi.ntnu.no>,
: Magnus L. Hetland <mlh at idt.ntnu.no> wrote:
:>cwebster at math.tamu.edu (Corran Webster) writes:
:>
:>I thought the Guido-approved version had a condition on the first as
:>well (i.e. an expansion of the standard while loop)?
:>
:>Thus:
:>
:>while 1:
:>  ...
:>and while something:
:>  ...

: It might be the Guido-approved version - I can't recall the exact form
: of the approved form.  If this is in fact it, then I think my proposal
: has a slight advantage over this in simplicity.  This form allows two
: tests (presuming something other than '1' is permitted after the first
: while), where my proposal has precisely one test for the loop, which
: seems more natural to me.

It seem wholy unnatural to me: the purpose of a while loops is to say
"while some condition is true, repeat these steps".  But you are
saying:  "while I do something and while some condition is true, do
something else and repeat".  Seemly terrible convoluted, IMO.

:>Of course, that doesn't remove the ugliness of the "while 1" but it
:>does alleviate the use of "break". I guess your suggestion actually
:>adds the syntax of "while:" for "while 1:" as well -- or is it only in
:>the use with "and while" that it is permitted?

: No, "while:" is not permitted without the "and while" later.  The precise
: grammar is

: while [':' suite 'and' 'while'] test ':' suite ['else' ':' suite]

: and it's implemented by simply inserting the optional suite before
: the test - this means the changes to the source are fairly simple.

Of course, it's the same as
  'while' true ':' suite 'if' 'not' test ':' 'break' suite

It just adds another syntax (and implimentation) to maintain.

: It seems to me that with this change, 'while 1:' will be used much
: less often, and it's not worth the additional complexity to make
: the '1' optional.

Depends on what you want.  No offense, but I would use "while 1" far
more than something less understandable by the general scripter/
programmer (even for newbies in other languages).  As a software
configuration manager who looks at dozens of developers' code files in
different languages, and having to write public tools and handle
porting projects, I find that dealing with obscure syntax is harmful,
leading to far more time debugging the problem than it took to design
the algorithm.

I'd be interested in knowing how many people would change from the
common idioms to this proposed syntax.

Folks, does anyone remember why RISC was invented?  Young students are
being encouraged to learn Python for their first language because the
syntax is simple and based on pretty well established computer science
idioms, methodologies and definitions.  Now we tell them to go learn
something that is only useful in one language, is complicated to follow
syntactically (thought nicely inserted in to the grammar, Corran), and
will likely not be used as much in large as more commonly learned and
understood semantic "tricks" (like while-break or while-done).
Experienced progammers are often using it because the language is
clear, concise and translates easily from pseudo-code (little special
syntax), among other reasons.

Seriously, a very well-defined, simple concept for iteration is
recursion: in some form most any application for a loop can be
expressed as some form of recursion (except in Fortran ;).  In many of
the right applications, recursion is easy-to-follow, intuitive and more
efficient.  Recursion (usually) requires no change in the language to
impliment.  Why don't we use recursion more often?  I think when people
answer that question themselves, they'll probably understand my point.

I'm not saying that innovation is bad, or that this addition is
necessarily bad (which I do think it is), just that it seems that some
people want to change the language for the wrong reasons.

Kudos for actually getting around to implimenting it, Corran.  Even
some of us detractors would probably like to see the code changes. :)

  -Arcege





More information about the Python-list mailing list