Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'rename': 0.07; 'wrapped': 0.07; 'iterate': 0.09; 'def': 0.10; 'gui': 0.11; 'suggest': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'immutability': 0.16; 'increment': 0.16; 'locating': 0.16; 'loops': 0.16; 'object).': 0.16; 'oct': 0.16; 'structure.': 0.16; 'wrote:': 0.17; '(in': 0.18; 'trying': 0.21; 'received:209.85.214.174': 0.21; 'example': 0.23; 'programming': 0.23; 'this:': 0.23; 'paul': 0.24; 'header :In-Reply-To:1': 0.25; '[1]': 0.27; 'am,': 0.27; 'message- id:@mail.gmail.com': 0.27; '(maybe': 0.29; 'tail': 0.29; 'writes:': 0.29; 'case,': 0.29; 'generally': 0.32; 'indexed': 0.33; 'programming,': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'next': 0.35; 'previous': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'your': 0.60; 'relationship': 0.60; '30,': 0.62; 'different': 0.63; 'difficulty': 0.65; 'andrea': 0.84 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 :content-type; bh=2XwOyGwN1lCuKDpPHUNKR72dhDLJgkZ46YbDMmxFzn4=; b=F1JuXHk8YTfrydi1kkhudc4qavKWUDdx9VT5wHYOJW8KnKLBVRF9SSI/Kfq7mgmEN4 HSpoJvnCzuLUwegF4HTZT4lHcZptLzdHNQ4c8DpwqFocCxSHMfaQU3i92sxAYilO1qM5 zEsqhXHKL4KUKRgmJJeNAbq3bhOnlHbCjx011Jlxr/DSZmTqYXXGYhb12QWGRh04Xn98 k2cHhN08wAyzLOYCdic77ESbweGDYxptiT/332jFuEHPHQp3RKUnhmOXMOEsder4DuND hMM5FJazTPpb70tqiX8HEVx+2QT1RmMDRL689Lz4knv3smwrnstVxkGPi/pHkyulLBuY yCrQ== MIME-Version: 1.0 In-Reply-To: <7xsj8xl1ct.fsf@ruckus.brouhaha.com> References: <7xsj8xl1ct.fsf@ruckus.brouhaha.com> Date: Tue, 30 Oct 2012 03:08:31 +1100 Subject: Re: Immutability and Python From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351526914 news.xs4all.nl 6855 [2001:888:2000:d::a6]:60709 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32390 On Tue, Oct 30, 2012 at 2:55 AM, Paul Rubin wrote: > andrea crotti 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"