Python and the need for speed

bartc bc at freeuk.com
Sat Apr 15 10:37:41 EDT 2017


On 15/04/2017 14:27, Marko Rauhamaa wrote:
> bartc <bc at freeuk.com>:

>>     while 1:
>>         body
>
> Why not say it like it is:
>
>    while True:
>        body
>
>> but it's more psychological; I don't want to use an idiom to denote an
>> endless loop, I want to be able to express it directly!
>
> C's:
>
>     for (;;)
>         statement
>
> I would call an idiom.

I don't like that either!

> Python's
>
>     while True:
>         body
>
> is about as straightforward as it gets.

In the syntax I normally use (based on Algol 68), the endless loop is:

    do
      body
    end

(well, actually I use do body od, but that may have raised some eyebrows).

'do', in the original Algol 68 syntax, was part of its 'for' statement, 
where you could leave out the parts you don't need. The full syntax is 
something like:

   for var := a to b by c while d do body od

If you leave out the first part you get a while loop. Leave out all 
except 'to b do', you get a repeat-n-times loop. And so on.

Elegant. (I don't do it that way, I have discrete loop types, plus my 
own variations. Devising syntax is so easy, the hard bit is knowing when 
to stop...)

>
>> Python's byte-code does at least optimise
>
> I don't understand why there's so much talk about CPython's bytecode on
> this list. That should only be of interest to active CPython developers.

What proportion of Python implementations depend on executing byte-code?

-- 
Bartc



More information about the Python-list mailing list