scope of function parameters (take two)

Chris Angelico rosuav at gmail.com
Tue May 31 04:04:29 EDT 2011


On Tue, May 31, 2011 at 5:17 PM, Henry Olders <henry.olders at mcgill.ca> wrote:
> Clearly, making a copy within the function eliminates the possibility of the
> side effects caused by passing in mutable objects. Would having the
> compiler/interpreter do this automatically make python so much different?

Yes, it would make Python quite different. If suddenly you couldn't
pass a mutable object to a function to get it muted (that sounds
wrong), then code will break. Also, there's a fairly serious
performance penalty to copying everything when it's not necessary. As
has been suggested, you can specifically and deliberately cause this
effect for any function(s) you wish to "protect" in this way; there's
no need to change the language's fundamentals to do it.

Chris Angelico



More information about the Python-list mailing list