Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10768

Re: Early binding as an option

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'parser': 0.05; 'function,': 0.07; 'terry': 0.07; 'python': 0.08; 'interpreter,': 0.09; 'wrote:': 0.15; 'altogether.': 0.16; 'arg': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lengths': 0.16; 'lookups': 0.16; 'names;': 0.16; 'redone': 0.16; 'reedy': 0.16; 'subject:Early': 0.16; 'pm,': 0.16; 'def': 0.16; 'aug': 0.19; 'repeated': 0.19; 'that?': 0.19; 'file,': 0.22; 'loop': 0.22; 'maybe': 0.22; 'header:In-Reply-To:1': 0.22; 'slots': 0.23; 'tue,': 0.23; 'code': 0.24; 'expect': 0.25; 'function': 0.26; "i'm": 0.27; 'objects': 0.28; 'message- id:@mail.gmail.com': 0.28; 'bound': 0.29; 'example': 0.30; 'definition': 0.30; 'binding': 0.30; 'lines': 0.31; "won't": 0.32; 'chris': 0.32; 'change.': 0.32; 'does': 0.32; 'rather': 0.33; 'to:addr:python-list': 0.34; 'it?': 0.34; 'calling': 0.34; 'there': 0.34; "can't": 0.34; 'crazy': 0.35; 'function.': 0.35; 'skip:@ 10': 0.35; 'define': 0.35; 'issue': 0.37; 'anything': 0.37; 'some': 0.37; 'but': 0.37; 'could': 0.37; 'getting': 0.38; 'received:google.com': 0.38; 'not,': 0.38; 'subject:: ': 0.38; 'execution': 0.38; 'somewhat': 0.38; 'something': 0.38; 'perhaps': 0.39; 'either': 0.39; "there's": 0.39; 'to:addr:python.org': 0.39; 'might': 0.39; 'received:74.125': 0.40; 'where': 0.40; 'results': 0.62; 'free': 0.63; 'huge': 0.64; 'ever': 0.65; 'cost': 0.65; 'benefit': 0.66; 'guarantee': 0.69; 'valued': 0.76; 'stupid': 0.91; 'presumably': 0.93; 'technique': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=GbBDjmZeuSp4UnHlc9LXPe7Bp6GlkEJTDFSHoQdPwVE=; b=o35STOWigV07b/WacHseUqjf8a1xSX0kLgPGSptxf5slTI9vcCGhspkICyh4z9bpFv oUuYbns+oxNqtL/vzlDTqpYHDGPYNDWHMNSfvsSHDGodbxs+jKP/776DYF7niV1blQWy uYGKW2KFy7dbRUU29rn6Z0G5heniteJJ0hAjs=
MIME-Version 1.0
In-Reply-To <j19mbp$985$1@dough.gmane.org>
References <CAPTjJmpWN1Tq-46UoHjh_-q9ahkivTWmLJR3_eF9iThHwXQnhA@mail.gmail.com> <j19mbp$985$1@dough.gmane.org>
Date Tue, 2 Aug 2011 23:08:48 +0100
Subject Re: Early binding as an option
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1807.1312322931.1164.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1312322931 news.xs4all.nl 23940 [2001:888:2000:d::a6]:54038
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10768

Show key headers only | View raw


On Tue, Aug 2, 2011 at 9:23 PM, Terry Reedy <tjreedy@udel.edu> wrote:
> On 8/2/2011 12:55 PM, Chris Angelico wrote:
>>
>> As I understand it, Python exclusively late-binds names; when you
>> define a function, nothing is ever pre-bound.
>
> By 'pre-bound' you presumably mean bound at definition time rather than call
> time. Default arg objects *are* pre-computed and pre-bound to internal slots
> at definition time.

Of course; that's a different issue altogether. No, I'm talking about
the way a tight loop will involve repeated lookups for the same name.

Unfortunately, there is no way - by definition - to guarantee that a
binding won't change. Even in the example of getting the lengths of
lines in a file, it's entirely possible for __len__ to rebind the
global name "len" - so you can't rely on the repeated callings of
len() to be calling the same function.

But who WOULD do that? It's somewhat ridiculous to consider, and
there's a huge amount of code out there that does these repeated calls
and does not do stupid rebindings in the middle. So Python permits
crazy behaviour at the cost of the performance of normal behaviour.

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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Early binding as an option Chris Angelico <rosuav@gmail.com> - 2011-08-02 23:08 +0100
  Re: Early binding as an option Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-03 20:16 +1000
    Re: Early binding as an option Chris Angelico <rosuav@gmail.com> - 2011-08-03 12:04 +0100
      Re: Early binding as an option Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-04 05:51 +1000
        Re: Early binding as an option Chris Angelico <rosuav@gmail.com> - 2011-08-03 23:24 +0100
        Re: Early binding as an option Chris Torek <nospam@torek.net> - 2011-08-04 19:49 +0000
      Re: Early binding as an option Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-08-03 22:16 +0200

csiph-web