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

Paul Prescod paul at prescod.net
Thu May 20 15:56:02 EDT 1999


"Michael P. Reilly" wrote:
> 
> It seem wholy unnatural to me: the purpose of a while loops is to say
> "while some condition is true, repeat these steps".  

"While 1 is true, repeat these steps." Only a longtime computer programmer
could consider that meaningful. Try it on someone on the street some day:
"while 1 could you hop on one foot until I tell you to stop?" Even "while
forever could you hop on one foot until I tell you to stop" doesn't make
sense. Let's try again: "could you hop on one foot forever until I tell
you to stop." Huh? If you intend to stop me then why are you telling me to
do it forever?

> But you are
> saying:  "while I do something and while some condition is true, do
> something else and repeat".  Seemly terrible convoluted, IMO.

As he pointed out, "do" would be a better spelling. "do" is also useful
for the common case where the test is supposed to follow the action.

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

If a language has syntax for a thing it *becomes* the idiom for the thing.
Or at least it should...

> Experienced progammers are often using it because the language is
> clear, concise and translates easily from pseudo-code (little special
> syntax), among other reasons.

Who puts "while 1" in pseudocode? My pseudocode uses "do/while",
personally. It is only when translating into computer languages that I
grit my teeth and either duplicate code or contort my "while" loop into an
"infinite" loop. "Do this forever...until I tell you to stop." Argh.

> 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.

Actually, I don't understand at all. Recursion is a feature built into
every modern programming language. Once you have it, you don't need loops.
But people prefer loops because they allow you to *say what you mean*
instead of contorting your naturally iterative logic into the language's
mold. So even languages that are inherently recursive usually give you
syntactic sugar to directly express iteration. 

The current proposal allows me to say what I mean about looping which
brings Python closer to being executable pseudo-code. do/while would be
even better but may not be worth the code breakage (though I am curious
how much code breakage there would really be).

-- 
 Paul Prescod  - ISOGEN Consulting Engineer speaking for only himself
 http://itrc.uwaterloo.ca/~papresco

"It's only a movie. People should get a life." 
 - George Lucas (http://www.nypost.com/news/9025.htm)




More information about the Python-list mailing list