[Python-ideas] Default arguments in Python - the return - running out of ideas but...

Steven D'Aprano steve at pearwood.info
Fri May 15 00:20:45 CEST 2009


On Thu, 14 May 2009 12:41:17 pm Bruce Leban wrote:

> >    def myfunc(a, b, *x=[]):
> > 
> > would be equivalent to what previous proposals would write as
> >
> >    def myfunc(a, b, *x=lambda: []):
>
> Explicit is better than implicit. There's a thunk getting created
> here, right? Don't you want that to be obvious? I do.

No, I don't want it to be obvious. I don't care about thunks, I care 
that x gets bound at runtime. I don't care what the implementation is: 
whether it is a thunk, eval(), voodoo or something else, just so long 
as it works.

As for your argument that it is better to be explicit, when you want to 
add two numbers and compare them with a third, do you write:

(1 .__add__(1)).__eq__(2)

instead of 

1+1 == 2? "Explicit is better than implicit", right?

No. 1+1=2 *is* explicit, because that's the Python syntax for addition. 
All those double-underscore method calls are implementation details 
that do not belong in "standard" Python code. If Python develops new 
syntax for late-binding of default arguments, that too will be 
explicit, and any reference to thunks (or any other mechanism) will be 
an implementation detail. The syntax shouldn't depend on the 
implementation.

lambda is already disliked by many people, including Guido. I don't 
think any suggestion that we make lambda more confusing by giving it 
two very different meanings ("create a thunk" inside function parameter 
lists, and "create a function" everywhere else) will be very popular on 
python-dev.



-- 
Steven D'Aprano



More information about the Python-ideas mailing list