Python 'for' loop is memory inefficient

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Mon Aug 17 15:41:55 EDT 2009


On 06:32 pm, pavlovevidence at gmail.com wrote:
>On Aug 17, 4:40 am, exar... at twistedmatrix.com wrote:
>>On 02:12 am, pavlovevide... at gmail.com wrote:
>>
>>
>>
>> >On Aug 16, 3:35 pm, sturlamolden <sturlamol... at yahoo.no> wrote:
>> >>On 16 Aug, 14:57, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
>>
>> >> >         Well, the alternative would be to have two keywords for
>> >>looping: one
>> >> > for your "simple" incrementing integer loop, and another for a 
>>loop
>> >>that
>> >> > operates over the elements of some collection type.
>>
>> >>A compiler could easily recognise a statement like
>>
>> >>   for i in range(n):
>>
>> >>as a simple integer loop.
>>
>> >It would be a simple to do if you were writing it for a different
>> >langauge was a lot less dynamic than Python is.  It'd be quite a
>> >complex hack to add it to CPython's compiler while maintaing the
>> >current highly dynamic runtime semantics and backwards compatibility,
>> >which is a design constraint of Python whether you like it or not.
>>
>>In your other message, you said this wasn't a legitimate CPython
>>complaint.  Here, you say that it would be a "complex hack" to 
>>implement
>>this in CPython.  "complex hack" has negative connotations in my mind.
>>This seems contradictory to me.
>
>Well, you missed the point, chief.
>
>It's not a legitimate complaint because you can use xrange, you don't
>need compiler magic to recognize and optimize range.

There's a lot of things in Python that I don't strictly *need*.  That 
doesn't mean that they wouldn't be welcome if I could have them. 
Getting rid of the range/xrange dichotomy would improve things.  Yes, I 
can work around it until the runtime is good enough to let me think 
about an *interesting* problem instead.  That makes it a legitimate 
complaint in my eyes.  You're welcome to disagree, of course, but do you 
have an argument more compelling than the one you give here?  It seems 
to me one could use it to argue a lot of Python out of existence. 
Chief.  (Seriously, "chief"?  What are you going for?  It sounds like 
condescension to me; what's the point of that?  I hope I'm just 
misreading you.)

Jean-Paul



More information about the Python-list mailing list