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


Groups > comp.lang.python > #32392

Re: Immutability and Python

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <andrea.crotti.0@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'skip:[ 20': 0.03; 'subject:Python': 0.05; 'rename': 0.07; 'suppose': 0.07; 'wrapped': 0.07; 'iterate': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'gui': 0.11; 'suggest': 0.11; 'downside': 0.16; 'immutability': 0.16; 'increment': 0.16; 'locating': 0.16; 'loops': 0.16; 'object).': 0.16; 'oct': 0.16; 'silly': 0.16; 'structure.': 0.16; 'wrote:': 0.17; '(in': 0.18; '>>>': 0.18; 'trying': 0.21; 'received:209.85.214.174': 0.21; 'cc:2**0': 0.23; 'example': 0.23; 'programming': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'paul': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '[1]': 0.27; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; 'represent': 0.28; '(maybe': 0.29; 'tail': 0.29; 'writes:': 0.29; 'url:mailman': 0.29; 'case,': 0.29; 'objects': 0.29; 'probably': 0.29; 'code': 0.31; 'point': 0.31; 'implement': 0.32; 'url:python': 0.32; 'generally': 0.32; 'url:listinfo': 0.32; 'indexed': 0.33; 'programming,': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'next': 0.35; 'but': 0.36; 'url:org': 0.36; 'depends': 0.36; 'should': 0.36; '(for': 0.37; 'previous': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'things': 0.38; 'instead': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'url:mail': 0.40; 'your': 0.60; 'easy': 0.60; 'relationship': 0.60; 'first': 0.61; '30,': 0.62; 'different': 0.63; 'skip:n 10': 0.63; 'become': 0.65; 'difficulty': 0.65; 'as:': 0.75; 'andrea': 0.84; 'composing': 0.84; 'easier,': 0.84; 'do:': 0.91; 'numbers:': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=X0P1Hy1wbWyixcmEJYrV7X0vIJ+rv5tflgrXrQzD9Gs=; b=wEiMd7LjYDRMwjuvQOOgPNGak3EB4FpswW05V36jn2qJKIrQz7rTDoDEQvbbmF8UM+ vVrMhVUb17neGVSFKvg4e75LFBPOUezumVouQKbS0Gb6ovQMEHNYE767k7G5MzvOam2o VJmfVKsP1BZqAA5TS5YTRnBGV24mjWHO6spkPhAdbAVndZKhx6GGa0xwPRFyDThYF1XZ 2GBeL+r9viYiNOMe3AU/czv5x3u9ZSWwnr8BIrLRXfOIkl7gfOPgQKKgVG4t2Scmsnag ehvL3sP9OJtKIcszieXP+JA1a3mUMpNDxqlq+6pTEjxO3AQl06uX+rT3W+gNXstSfv70 bfSw==
MIME-Version 1.0
In-Reply-To <CAPTjJmry6FX_xBwrABjEEDF1N0V=OiAc0qXBSzViwHLA_+jB3g@mail.gmail.com>
References <mailman.3018.1351524004.27098.python-list@python.org> <7xsj8xl1ct.fsf@ruckus.brouhaha.com> <CAPTjJmry6FX_xBwrABjEEDF1N0V=OiAc0qXBSzViwHLA_+jB3g@mail.gmail.com>
Date Mon, 29 Oct 2012 16:33:03 +0000
Subject Re: Immutability and Python
From andrea crotti <andrea.crotti.0@gmail.com>
To Chris Angelico <rosuav@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3026.1351528391.27098.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351528391 news.xs4all.nl 6919 [2001:888:2000:d::a6]:45309
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32392

Show key headers only | View raw


2012/10/29 Chris Angelico <rosuav@gmail.com>:
> 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"
> --
> http://mail.python.org/mailman/listinfo/python-list


Yes the name should be changed, but the point is that they are both
ways to implement the same thing.

For example suppose I want to have 10 objects (for some silly reason)
that represent the next number, in the first case I would do:

numbers = [NumWrapper(orig.number)] * 10
for num in numbers:
    num.increment()

while in the second is as simple as:
numbers = [orig.next_number()] * 10

composing things become much easier, but as a downside it's not always
so easy and convienient to write code in this way, it probably depends
on the use case..

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


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