Immutability and Python

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Oct 29 12:00:31 EDT 2012



----- Original Message -----
> 2012/10/29 Jean-Michel Pichavant <jeanmichel at sequans.com>:
> >
> > "return NumWrapper(self.number + 1) "
> >
> > still returns a(nother) mutable object.
> >
> > So what's the point of all this ?
> >
> > JM
> >
> 
> Well sure but it doesn't modify the first object, just creates a new
> one.  There are in general good reasons to do that, for example I can
> then compose things nicely:
> 
> num.increment().increment()
> 
> or I can parallelize operations safely not caring about the order of
> operations.
> 
> But while I do this all the time with more functional languages, I
> don't tend to do exactly the same in Python, because I have the
> impression that is not worth, but maybe I'm wrong..
> 

In an OOP language num.increment() is expected to modify the object in place.
So I think you're right when you say that functional languages technics do not necessarily apply to Python, because they don't.

I would add that what you're trying to suggest in the first post was not really about immutability, immutable objects in python are ... well immutable, they can be used as a dict key for instance, your NumWrapper object cannot.


JM



-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list