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


Groups > comp.lang.python > #90255

Re: functions, optional parameters

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'attribute': 0.07; 'compiler': 0.07; 'debug': 0.07; 'tries': 0.07; 'differently.': 0.09; 'immutable': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'suggest': 0.14; "wouldn't": 0.14; "(it's": 0.16; 'binding,': 0.16; 'bugs.': 0.16; 'complicated,': 0.16; 'definition;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mutable': 0.16; 'optional': 0.16; 'result;': 0.16; 'subject:parameters': 0.16; 'language': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'simpler': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'rest': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'easier': 0.31; "d'aprano": 0.31; 'idea,': 0.31; 'int,': 0.31; 'steven': 0.31; 'cases': 0.33; 'guess': 0.33; 'could': 0.34; 'common': 0.35; 'late': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'introducing': 0.36; 'method': 0.36; 'wrong': 0.37; 'list,': 0.38; 'pm,': 0.38; 'extremely': 0.39; 'enough': 0.39; 'how': 0.40; 'expression': 0.60; 'break': 0.61; 'simple': 0.61; 'first': 0.61; 'such': 0.63; 'chance': 0.65; 'anything.': 0.68; 'default': 0.69; 'fact,': 0.69; 'therefore': 0.72; 'evaluate': 0.72; 'obvious': 0.74; '2015': 0.84; "it'd": 0.84; 'optimized,': 0.84; 'technically': 0.84; 'absolutely': 0.87; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=7OyGbfJcZ3/xOuVmSKYVyI5hcoh6eorRbH3/pdOPEcw=; b=rhmmHxdGu+W41NDI/kfJtC1VovCaUpkx4NqSsucRcmaGZ0eeG5E6BlUVy+Ll5ElCOV 8gr5L6D0QZAmL9oO79IMIxKR2+q0WepcxKWmixy2kOx7CFfR2Nm3TCvGAMYp6nzwvXDO v7YS8gt4tf4QAm/U+ViJ24+3V4WUbMb8Frjsx1MgTzaGtX9Dnw/RyILk0gJHaoE/LnVN TQI4NRZy+vRnj7+b2/HPMIY+iaAneaW8h+DrMhGI2R4aJfD3feOyQOwFHP0Qpf7XhJXQ IEOuhVXm0PoBDcQ57423jBEgygpNhIV9I6wG7f8YXz2Om+B0zxno6avyxfdoR+MzHouA 21Uw==
MIME-Version 1.0
X-Received by 10.43.39.1 with SMTP id tk1mr5156626icb.26.1431228780126; Sat, 09 May 2015 20:33:00 -0700 (PDT)
In-Reply-To <554ec664$0$13001$c3e8da3$5496439d@news.astraweb.com>
References <72lu1cxvmg.ln2@news.c0t0d0s0.de> <554cd511$0$12979$c3e8da3$5496439d@news.astraweb.com> <ui2v1cx5co.ln2@news.c0t0d0s0.de> <554ec664$0$13001$c3e8da3$5496439d@news.astraweb.com>
Date Sun, 10 May 2015 13:33:00 +1000
Subject Re: functions, optional parameters
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.298.1431228783.12865.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431228783 news.xs4all.nl 2923 [2001:888:2000:d::a6]:46190
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90255

Show key headers only | View raw


On Sun, May 10, 2015 at 12:45 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> This is the point where some people try to suggest some sort of complicated,
> fragile, DWIM heuristic where the compiler tries to guess whether the user
> actually wants the default to use early or late binding, based on what the
> expression looks like. "0 is an immutable int, use early binding; [] is a
> mutable list, use late binding." sort of thing. Such a thing might work
> well for the obvious cases, but it would be a bugger to debug and
> work-around for the non-obvious cases when it guesses wrong -- and it will.

What you could have is "late-binding semantics, optional early binding
as an optimization but only in cases where the result is
indistinguishable". That would allow common cases (int/bool/str/None
literals) to be optimized, since there's absolutely no way for them to
evaluate differently.

I personally don't think it'd be that good an idea, but it's a simple
enough rule that it wouldn't break anything. As far as anyone's code
is concerned, the rule is "late binding, always". In fact, that would
be the language definition; the rest is an optimization. (It's like
how "x.y()" technically first looks up attribute "y" on object x, then
calls the result; but it's perfectly reasonable for a Python
implementation to notice this extremely common case and do an
"optimized method call" that doesn't actually create a function
object.) The simpler the rule, the easier to grok, and therefore the
less chance of introducing bugs.

ChrisA

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


Thread

functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-08 13:59 +0200
  Re: functions, optional parameters Rustom Mody <rustompmody@gmail.com> - 2015-05-08 05:09 -0700
    Re: functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-08 14:36 +0200
  Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-08 22:39 +1000
    Re: functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-08 14:57 +0200
  Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 01:24 +1000
    Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-09 02:02 +1000
      Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 03:36 +1000
        Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-09 03:49 +1000
          Re: functions, optional parameters Mel Wilson <mwilson@the-wire.com> - 2015-05-08 18:49 +0000
          Re: functions, optional parameters Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-09 13:41 +1200
            Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-09 12:05 +1000
              Re: functions, optional parameters Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-09 19:27 +1200
          Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 12:52 +1000
    Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 03:26 +1000
    Re: functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-08 17:50 +0200
      Re: functions, optional parameters Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-09 10:57 -0600
      Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-10 13:33 +1000
        Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-10 15:20 +1000
          Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-10 18:59 +1000
      Re: functions, optional parameters Rustom Mody <rustompmody@gmail.com> - 2015-05-09 20:35 -0700
        Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-10 15:25 +1000
      Re: functions, optional parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-10 12:45 +1000
        Re: functions, optional parameters Dave Angel <davea@davea.name> - 2015-05-10 07:25 -0400
        Re: functions, optional parameters Chris Angelico <rosuav@gmail.com> - 2015-05-11 00:39 +1000
        Re: functions, optional parameters Michael Welle <mwe012008@gmx.net> - 2015-05-11 07:58 +0200
    Re: functions, optional parameters Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-08 09:48 -0600

csiph-web