Immutability and Python
Paul Rubin
no.email at nospam.invalid
Mon Oct 29 11:55:14 EDT 2012
andrea crotti <andrea.crotti.0 at gmail.com> writes:
> and we want to change its state incrementing the number ...
> the immutability purists would instead suggest to do this:
> def increment(self):
> return NumWrapper(self.number + 1)
Immutability purists would say that numbers don't have "state" and if
you're trying to change a number's state by incrementing it, that's not
immutability. You end up with a rather different programming style than
imperative programming, for example using tail recursion (maybe wrapped
in an itertools-like higher-order function) instead of indexed loops to
iterate over a structure.
More information about the Python-list
mailing list