functions, list, default parameters

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Nov 2 08:16:58 EDT 2010


On Tue, 02 Nov 2010 00:40:17 -0700, Chris Rebert wrote:

> On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano
> <steve at remove-this-cybersource.com.au> wrote:
>> On Thu, 21 Oct 2010 19:53:53 -0700, John Nagle wrote:
>>>> This is a common newbie stumbling-block: Don't use lists (or anything
>>>> mutable) as default argument values
>>>
>>>      That really should be an error.
>>
>> No it shouldn't. Punishing everybody for a newbie mistake that nobody
>> makes twice would be the error.
>>
>> Default mutable arguments have their place
> 
> But it's a rather obscure one where it is almost never strictly
> necessary to venture.

Very few language features are *strictly* necessary. I mean, all you 
really need is the ability to set the current memory location, a way to 
read and write to it, and a way to branch. Everything else is just gravy.

Not that I'm suggesting we should all use Turing machines, but there are 
many things which aren't strictly necessary but are nice to have.

In any case, this discussion is pointless. There is code out there that 
uses this feature, whether you (generic you) like it or not, and changing 
the behaviour *can't* happen until the moratorium ends. Even if there was 
consensus to make this change -- and there won't be -- it almost 
certainly won't happen before Python 4000. 

Even if it did happen, adding extra type-checks to every def statement 
with a default value, or adding extra complexity to the parser, won't and 
can't catch every mutable default because there is no way of telling 
whether an arbitrary object is mutable. It will just slow down the 
language for bugger-all benefit.


-- 
Steven



More information about the Python-list mailing list