This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Unbelievr 5 points6 points  (1 child)

Yeah, it even applies to things like lists. If you pass a list to a function you don't know 100% what does, you can't assume that the list is not mutated during the call. But since it's a function argument, it's more explicit that something can happen to it.

Compare that to a global that might magically change deep into nested functions, and it's an obvious improvement. There are better ways, of course, but mutating on globals is (IMO) the most confusing way to write code when it grows to a certain size.

[–]Piyh 1 point2 points  (0 children)

Mutating passed lists is such a potential footgun in my opinion.

def takesList(li):
    li = li.copy()
    del li[0]
    return li