Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'debug': 0.03; 'assign': 0.04; 'parser': 0.05; 'interpreter': 0.07; 'symbols': 0.07; 'python': 0.08; 'interpreter,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'tracing': 0.09; 'am,': 0.13; 'wrote:': 0.15; 'explicitely': 0.16; 'optimizing': 0.16; 'redone': 0.16; 'subject:Early': 0.16; 'def': 0.16; 'maybe': 0.22; 'header :In-Reply-To:1': 0.22; 'thus': 0.23; 'code': 0.24; 'expect': 0.25; 'function': 0.26; 'bound': 0.29; 'binding': 0.30; 'chris': 0.32; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'header:User-Agent:1': 0.34; 'it?': 0.34; 'function.': 0.35; 'skip:@ 10': 0.35; 'certain': 0.36; 'idea': 0.36; 'anything': 0.37; 'some': 0.37; 'could': 0.37; 'received:org': 0.38; 'not,': 0.38; 'subject:: ': 0.38; 'execution': 0.38; 'something': 0.38; 'think': 0.38; 'perhaps': 0.39; 'header:Mime-Version:1': 0.39; 'help': 0.39; 'either': 0.39; 'to:addr:python.org': 0.39; 'might': 0.39; 'where': 0.40; 'results': 0.62; 'free': 0.63; 'production': 0.65; 'ever': 0.65; 'benefit': 0.66; 'guarantee': 0.69; 'valued': 0.76; 'binding.': 0.84; 'interesting,': 0.84; 'technique': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Gelonida N Subject: Re: Early binding as an option Date: Wed, 03 Aug 2011 00:21:03 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: unicorn.dungeon.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 "" In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312323680 news.xs4all.nl 23898 [2001:888:2000:d::a6]:49072 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10769 On 08/03/2011 12:08 AM, Chris Angelico wrote: > With the local-variable-snapshot technique ("len = len"), can anything > be optimized, since the parser can guarantee that nothing ever > reassigns to it? If not, perhaps this would be a place where something > might be implemented: > > @const(len,max) # maybe this > def maxline(f): > @const len,max # or this > n = 0 > for line in somefile: > n = max(n,len(line)) > return n > > Some notation like this could tell the interpreter, "I don't expect > 'len' or 'max' to be rebound during the execution of this function. > You're free to produce wrong results if either is." > > So... Would this potentially produce wrong results? Would it be of any > use, or would its benefit be only valued in times when the whole > function needs to be redone in C? > > Chris Angelico I think the idea of having pragmas / directives to tell the interpreter that certain symbols could be bound early is intersting and might help optimizing some inner loops without having to explicitely assign to local vars. On the other hand: It might be interesting, that the early binding would just take place when python is invoked with -O Thus you could still do a lot of debug / tracing magic during development and only production code would do the late binding.