Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6736

Re: scope of function parameters (take two)

From Terry Reedy <tjreedy@udel.edu>
Subject Re: scope of function parameters (take two)
Date 2011-05-31 12:15 -0400
References <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> <F4EAD1ED-563D-4D6E-A50C-68308A9F26B7@mcgill.ca> <BANLkTin5exEpDkE3on3BAaWwHOjpg_vC8g@mail.gmail.com> <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca>
Newsgroups comp.lang.python
Message-ID <mailman.2318.1306858536.9059.python-list@python.org> (permalink)

Show all headers | View raw


On 5/31/2011 3:17 AM, Henry Olders wrote:

> Clearly, making a copy within the function eliminates the possibility of
> the side effects caused by passing in mutable objects.

Mutable objects and mutating methods and functions are a *feature* of 
Python. If you do not like them, do not use them.

 > Would having the  compiler/interpreter do this automatically
 > make python so much different?

Yes. How would you then write a function like list.sort or list.pop?

It is fundamental that parameters are simply local names that must be 
bound as part of the calling process. After that, they are nothing special.

Python is a language for adults that take responsibility for what they 
do. If you do not like argument-mutating functions, then do not write 
them and do not use them (without making a copy yourself).

Python was not designed to model timeless immutable mathematics. It is 
an information-object manipulation language and in real life, we mutate 
collections and associations all the time.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: scope of function parameters (take two) Terry Reedy <tjreedy@udel.edu> - 2011-05-31 12:15 -0400

csiph-web