[Python-3000] pre-PEP: Default Argument Expressions
Chris Rebert
cvrebert at gmail.com
Thu Feb 15 03:20:31 CET 2007
Josiah Carlson wrote:
> "BJörn Lindqvist" <bjourne at GMAIL.COM> wrote:
>> On 2/14/07, Josiah Carlson <jcarlson at uci.edu> wrote:
>>> Chris Rebert <cvrebert at gmail.com> wrote:
>>>> Requesting comments on the following pre-PEP. pybench runs both with and
>>>> without the patch applied would also be appreciated.
>>>> - Chris R
>>> One Glyph Lefkowitz posted today [1] in response to dynamic attribute
>>> access the following, which is surely applicable here.
>> To be fair, the two ideas are fairly different. Dynamic attribute
>> access was about adding new syntax which makes the language more
>> complex. This idea is more about fine-tuning existing syntax; it does
>> not add to the language, it just makes it different.
>
> There are about a dozen different syntax proposals in the pre-PEP to
> determine whether something is executed at compilation or during call.
> Re-read it.
Those syntaxes were only raised during discussion of changing default
argument semantics. If you read the PEP, it doesn't endorse any of them.
I'm against adding new syntax. However, that could always change based
on community feedback.
> [snip]
>>> 1a) Proof as to what is to be gained over an explicit if statement or
>>> conditional expression.
>> Two less lines of code? It is hard to grep for it, but I bet there are
>> a few hundred occurrences the following in the standard library:
>>
>> def something(x = None):
>> if x is None:
>> x = [1, 2, 3] # <- default
>
> If some 500+ examples of dynamic attribute access in the Python standard
> library wasn't sufficient, than the 'few hundred' surely isn't,
> especially without actual counts. Yes, coming up with good counts is
> hard, but that's one of the requirements Glyph pointed out. If no one
> is willing to go through and see what it would fix, then it's obviously
> not worth it.
Under "Compatibility Issues" in the PEP, I mention that my
statistics-generating script found in the standard library (among other
things):
total number of default arguments with a value of None: 1813 (47.4%
of all default arguments)
total number of comparisons to None: 940
Yes, these aren't specific counts of uses of the 'x=None...if x is None:
x=whatever' idiom, but you can't get much closer without looking over
the files manually.
> [snip]
>>> or
>>> 1b) A cost/benefit analysis of the time it would take to "fix" the
>>> standard library and/or user code with any of the provided new
>>> syntax/semantics.
[snip]
I'm going to respond to this in the original email that asked these
questions.
- Chris Rebert
More information about the Python-3000
mailing list