What is a function parameter =[] for?

Chris Angelico rosuav at gmail.com
Thu Nov 19 12:45:14 EST 2015


On Fri, Nov 20, 2015 at 4:30 AM, BartC <bc at freeuk.com> 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([])
>
> You just write fn() instead. But it shouldn't come at the cost of completely
> different semantics! Because then it can't really be called a default value
> at all.
>

Do you understand the concept of "mutable objects"? Don't even try to
discuss mutable function defaults until you do.

If your language simply has no mutable objects, then sure, it's easy
to understand function defaults! There's no such thing as early or
late binding; in fact, you can even super-late-bind, where you don't
actually call a function until its *return value* is being used (as
long as that function has no side effects). But as soon as objects are
capable of retaining their identities while changing their values, you
need an object model that (a) distinguishes between identity and
value, and (b) allows some definition of early or late binding,
because it *will* matter.

> if you write A=B then something of B needs to have been copied into
> A, even if it's just the reference that B contains. Otherwise it would be
> difficult to get A to refer to the same object as B.

Please, PLEASE, go and read/watch Ned's PyCon talk (the one I linked
you to earlier). Don't post another word on this subject until you
comprehend what he is saying.

ChrisA



More information about the Python-list mailing list