Python and the need for speed

Steven D'Aprano steve at pearwood.info
Wed Apr 12 02:48:50 EDT 2017


On Tue, 11 Apr 2017 21:10:56 -0700, Rick Johnson wrote:

> high level languages like Python should make it difficult, if not
> impossible, to write sub-
> optimal code (at least in the blatantly obvious cases).


You mean that Python should make it impossible to write:

    near_limit = []
    near_limit.append(1)
    near_limit = len(near_limit)


instead of:

    near_limit = 1


? I look forward to seeing your version of RickPython that can enforce 
that rule.

Oh, in case you think I'm making this up, this example came from some 
real-life code:

https://mail.python.org/pipermail//python-list/2016-August/712673.html



Here's another example:

    answer = 0
    for i in range(10):
        answer += 1


instead of 

    answer = 10




So... how exactly does the compiler prohibit stupid code?


-- 
Steve



More information about the Python-list mailing list