Looping [was Re: Python and the need for speed]

Terry Reedy tjreedy at udel.edu
Sun Apr 16 13:07:05 EDT 2017


On 4/16/2017 11:35 AM, Michael Torrie wrote:
> On 04/16/2017 07:57 AM, bartc wrote:
>> But people just don't want it.
>>
>> /That/ is what surprises me, when people reject things that to me are
>> no-brainers.

Whereas to me, it is a no-brainer that we are better off *without* 
multiple while/loop constructs.

> I simply don't care about these missing loop constructs.

I do ;-)  I consider the current simplicity a feature.

 > Python works
> great for what I use it for, and apparently works well for many people.

The great majority* of 'repetition with variation' is sequentially 
processing items from a collection.  Python does that nicely with 'for 
item in collection: process(item)'.  While-loops take care of everthing 
else.

*I grepped 3.6.1 .../lib/*.py with the REs '^ *while ' and '^ *for ', 
recursing into subdirectories, including tests and a few packages in 
site-packages.  These got 1389 and 9842 hits respectively. I am opposed 
to adding syntax to subdivide the 12% of looping using 'while'.  (As a 
note, '^ *while True' had 363 hits, about 1/4 of while loops.)

 > I have yet to find a loop that I couldn't construct with Python's
 > apparently-limited constructs.

For-loops, 'limited' to iterating through collections (iterables), cover 
at least 80% of cases.  While-loops + continue/break easily cover the 
remaining cases of linear repetition.  Branching repetition, as in naive 
Fibonacci calculation and tree processing, is more easily done with 
recursion.

-- 
Terry Jan Reedy




More information about the Python-list mailing list