Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32390
| References | <mailman.3018.1351524004.27098.python-list@python.org> <7xsj8xl1ct.fsf@ruckus.brouhaha.com> |
|---|---|
| Date | 2012-10-30 03:08 +1100 |
| Subject | Re: Immutability and Python |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3024.1351526914.27098.python-list@python.org> (permalink) |
On Tue, Oct 30, 2012 at 2:55 AM, Paul Rubin <no.email@nospam.invalid> wrote: > andrea crotti <andrea.crotti.0@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. In that case, rename increment to next_integer and TYAOOYDAO. [1] You're not changing the state of this number, you're locating the number which has a particular relationship to this one (in the same way that GUI systems generally let you locate the next and previous siblings of any given object). ChrisA [1] "there you are, out of your difficulty at once" - cf WS Gilbert's "Iolanthe"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Immutability and Python andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-29 15:20 +0000
Re: Immutability and Python Paul Rubin <no.email@nospam.invalid> - 2012-10-29 08:55 -0700
Re: Immutability and Python Chris Angelico <rosuav@gmail.com> - 2012-10-30 03:08 +1100
Re: Immutability and Python andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-29 16:33 +0000
Re: Immutability and Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-29 23:02 +0000
Re: Immutability and Python rusi <rustompmody@gmail.com> - 2012-10-30 09:22 -0700
Re: Immutability and Python Neal Becker <ndbecker2@gmail.com> - 2012-10-30 16:45 -0400
Re: Immutability and Python rusi <rustompmody@gmail.com> - 2012-10-30 20:21 -0700
Re: Immutability and Python Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-11-08 08:38 +0100
csiph-web