Ian Kelly wrote:
On Thu, Dec 22, 2011 at 7:10 PM, alex23 <wuwe...@gmail.com> wrote:
On Dec 22, 6:51 pm, Rolf Camps <r...@roce.be> wrote:
I'm afraid it's dangerous to encourage the use of '[]' as assignment to
a parameter in a function definition. If you use the function several
times 'default' always points to the same list.
>>
I appreciate the concern, but adding a default argument guard would
not only obscure the code. It's irrelevant, as you recognise, because
no matter what, it's going to make copies of the default argument.

It's only irrelevant in the immediate context of the code you posted.
But when Joe Novice sees your code and likes it and duplicates it a
million times without receiving any warning about it, he's eventually
going to write a function that modifies its default list argument, and
he'll be in for a nasty surprise when he does.

And then he will learn about it and not make the mistake again (or if he does, it take much less time to figure it out).

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to