Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'programmer': 0.03; 'great.': 0.07; 'indices': 0.07; 'think,': 0.07; 'transform': 0.07; 'arrays': 0.09; 'high-level': 0.09; 'integers': 0.09; 'lawrence': 0.09; 'pep': 0.09; 'sure,': 0.09; 'terms,': 0.09; 'vast': 0.09; 'yeah,': 0.09; 'python': 0.11; 'array.': 0.16; 'index.': 0.16; 'integers,': 0.16; 'iterator': 0.16; 'loops': 0.16; 'porting': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'implementing': 0.19; '>>>': 0.22; 'code,': 0.22; "aren't": 0.24; 'world,': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'correct': 0.29; 'then.': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'software,': 0.31; 'usually': 0.31; 'fault': 0.31; 'up.': 0.33; 'implemented': 0.33; 'except': 0.35; 'anybody': 0.35; 'received:google.com': 0.35; "didn't": 0.36; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'improved': 0.60; 'introduced': 0.61; 'skip:* 10': 0.61; 'simple': 0.61; 'first': 0.61; 'back': 0.62; 'real': 0.63; 'such': 0.63; '2015': 0.84; 'iterative': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=IY5bcRM4nxez54SMP5dJjMq0EbSjIE88ePfxzaYSNUg=; b=ZPF5LuFQH2LjnWqCrs71hZ+yjw7KJKj5x0nBVEWyH1IRGSGroALZAYyl+FqTn4w0M3 1Yzl+yDa+weePvrEBCa8YrVSGXHtV1//lp+bSV8jWjHZTpuIzIsuc4mMCSJTIzjHYnNe j3B+CiBa06RYRIHcE4ATddi/9dtRdvzlo8q9wJGGBubHNGivbv81/1Qr6huR+YG4jcMI mcfhoTZW7bApOvPTJQsl8Yd9852nh0Bxovfmt6vUwWGN6M7VNrkD/4mh+m/mWulJjMvk OtqnzclnNZXXKCGx+i1qjzbOK1TGLWlrM+zXiBGe9FuHCd/AGlnplP67WirJs+q6yEI9 BPww== X-Received: by 10.43.64.144 with SMTP id xi16mr21779078icb.20.1430602348404; Sat, 02 May 2015 14:32:28 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <87k2wtvbx1.fsf@Equus.decebal.nl> <_M61x.477467$Ek.357048@fx07.am4> From: Ian Kelly Date: Sat, 2 May 2015 15:31:47 -0600 Subject: Re: l = range(int(1E9)) To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430602350 news.xs4all.nl 2884 [2001:888:2000:d::a6]:51852 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89802 On Sat, May 2, 2015 at 1:51 PM, BartC wrote: > On 02/05/2015 20:15, Mark Lawrence wrote: >> >> On 02/05/2015 19:34, BartC wrote: > > >>> OK, so it's the programmer's fault if as fundamental a concept as a >>> for-loop ranging over integers is implemented inefficiently. He has to >>> transform it into high-level terms, or has to reconstruct it somehow >>> using a while-loop and an incrementing loop index. > > >> I give up. > > > So do I, I think, if no-one is willing to admit that the original way of > implementing range() was a glaring mistake. range() was and is a *convenience* function. In the real world, the vast majority of for loops are over arrays or other containers, not integers, and those that aren't are usually very small. In non-toy code, using a for loop to count to a billion is highly unusual. So yeah, for a programmer porting code to Python who needed to loop over an array, the correct approach would be to actually loop over the *array* in place of the indices of the array. I don't know why you make this out to be such a big deal; it's a simple conversion. Would it have been better if range() had been implemented as xrange() from the beginning? Sure, that would have been great. Except for one small detail: the iterator protocol didn't exist back then. That wasn't introduced until PEP 234 in Python 2.1, which means that the xrange() function wasn't even *possible* before then. I don't think anybody would claim that Python was perfect when it was first introduced (nor is it perfect now). Like all other software, it has improved over time as a result of iterative refinement.