What is a function parameter =[] for?
BartC
bc at freeuk.com
Fri Nov 20 07:39:58 EST 2015
On 20/11/2015 12:12, Ned Batchelder wrote:
> On Friday, November 20, 2015 at 6:59:54 AM UTC-5, BartC wrote:
>> On 20/11/2015 01:05, Steven D'Aprano wrote:
>>> On Fri, 20 Nov 2015 04:30 am, BartC wrote:
>>>
>>>> On 19/11/2015 16:01, Steven D'Aprano wrote:
>>> [...]
>>>
>>>> The whole concept of 'mutable' default is alien to me. A default is just
>>>> a convenient device to avoid having to write:
>>>>
>>>> fn(0) or fn("") or fn([])
>>>
>>> Says who?
>>
>> People who want to avoid having to write:
>>
>> fn(0) or fn("") or fn([])
>
> I think we all understand by now that you are unhappy with what happens
> in Python with mutable defaults. We get it. You are not alone. Lots of
> people are surprised by this. But it is how Python works.
>
> I'm not sure what your goal is at this point. Are you:
>
> 1) still unsure what the behavior is, or
> 2) trying to understand why it behaves that way, or
> 3) hoping to change Python, or
> 4) trying to convince us that your language is better, or
> 5) something else?
Mostly 5. (With a bit of 4. However that language is not something I'm
selling or pushing. It's just something different used as a contrast.).
What's bothering me is:
* The large amount of mumbo-jumbo used to describe what's going on
* The insistence (I think largely from Steven) that the way this feature
works is good rather than bad
* The refusal to acknowledge that the def fn(a=[]) syntax is misleading.
(What value will a have when you call fn()? The true answer is that you
can't tell.)
* The persistent nonsense that somehow [] is mutable (what happens is
that [] is assigned to a variable, and /that/ is mutable) (And I will
probably get some flak now because 'assign' and 'variable' are
meaningless in Python!)
* And above, where I lay out /why/ people want to use the feature, so
that the function can take care of some details, even that is refuted.
--
Bartc
More information about the Python-list
mailing list