[Python-Dev] Eliminating loops

Josiah Carlson jcarlson at uci.edu
Sat Jul 29 10:05:53 CEST 2006


"Charles Vaughn" <cvaughn at gmail.com> wrote:
> I'm looking for a way of modifying the compiler to eliminate any loops and
> recursion from code.  It's for a high speed data processing application.
> The alternative is a custom language that is little more than gloryfied
> assembly.  I'd like to be able to use everything else around Python, but we
> can't allow the users to create more than O(1) complexity.

One of the larger, if not largest advances in computer science in the
last 50 years was the design and implementation of looping as a
construct, not just an artifact of structured gotos, but as a method of
implementing algorithms.

With your proposed removal of loops and recursion, you are effectively
saying that users should be given a turing machine because you are
afraid of them doing foolish things with the language.  Well, since the
user is going to do foolish things with the language anyways, about all
you can really do is to test, analyze, and verify.  Oh, and educate.

What do I mean?  If your users have access to sequences of any type, and
they can't perform 'x in y', then they are going to write their own
contains/index function...

def index(x,y):
    if x == y[0]:
        return 0
    elif x == y[1]:
        return 1
    elif x == y[2]:
        return 2
    ...

If they aren't given acess to sequences, then they will do what used to
be done in QuakeC back in the day...

def index(x,y):
    if x == y0:
        return 0
    elif x == y1:
        return 1
    elif x == y2:
        return 2
    ...


While algorithm design and analysis isn't something that everyone can do
(some just can't handle the math), the users really should understand at
least a bit about algorithms before they work on the "high speed data
processing" application.

 - Josiah



More information about the Python-Dev mailing list