Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'compiler': 0.05; 'correct,': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'zero.': 0.09; 'language': 0.14; 'cases': 0.15; 'chatting': 0.16; 'decimal.': 0.16; 'enlighten': 0.16; 'inf': 0.16; 'knows?': 0.16; 'least,': 0.16; 'nan': 0.16; 'optimised': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'spotted': 0.16; 'wrote:': 0.17; 'certainly': 0.17; 'pointed': 0.17; '>>>': 0.18; 'do.': 0.21; 'subject:skip:i 10': 0.22; 'example': 0.23; "i've": 0.23; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'topic': 0.27; 'header:X-Complaints-To:1': 0.28; 'subject:list': 0.28; 'chris': 0.28; '>>>>': 0.29; 'cases.': 0.29; "d'aprano": 0.29; 'steven': 0.29; "i'm": 0.29; 'fri,': 0.30; 'code': 0.31; 'from:addr:yahoo.co.uk': 0.32; 'could': 0.32; 'int': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'another': 0.33; 'desirable': 0.35; 'nov': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'rather': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'subject:-': 0.40; 'header:Received:5': 0.40; 'hoping': 0.72; 'coral': 0.84; 'float,': 0.84; 'colleague': 0.91; 'either:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Multi-dimensional list initialization Date: Fri, 09 Nov 2012 07:27:35 +0000 References: <50978323$0$6908$e4fe514c@news2.news.xs4all.nl> <5098d2ac$0$29980$c3e8da3$5496439d@news.astraweb.com> <5099bf7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <509ca4b5$0$29980$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-146-8-197.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 In-Reply-To: <509ca4b5$0$29980$c3e8da3$5496439d@news.astraweb.com> X-Antivirus: avast! (VPS 121108-1, 08/11/2012), Outbound message X-Antivirus-Status: Clean 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352446120 news.xs4all.nl 6900 [2001:888:2000:d::a6]:55168 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33000 On 09/11/2012 06:37, Steven D'Aprano wrote: > On Fri, 09 Nov 2012 17:07:09 +1100, Chris Angelico wrote: > >> On Fri, Nov 9, 2012 at 12:39 PM, Mark Lawrence >> wrote: >>> On 07/11/2012 01:55, Steven D'Aprano wrote: >>>> >>>> >>>> Who knows? Who cares? Nobody does: >>>> >>>> n -= n >>>> >>>> >>> But I've seen this scattered through code: >>> >>> x := x - x - x >> >> Can you enlighten us as to how this is better than either: >> x := -x >> or >> x := 0 - x >> ? I'm not seeing it. > > I'm hoping that Mark intended it as an example of crappy code he has > spotted in some other language rather than a counter-example of something > you would do. Correct, CORAL 66 and pointed out to me by a colleague when another team member had resigned. > > To be pedantic... there may very well be some (rare) cases where you > actually do want x -= x rather than just x = 0. Consider the case where x > could be an INF or NAN. Then x -= x should give x = NAN rather than zero. > That may be desirable in some cases. Interesting what comes up when we get chatting here. I hope we don't get punished for going off topic :) > > At the very least, the compiler should NOT optimize away x = x - x to > x = 0 if x could be a float, complex or Decimal. > X was an int so almost certainly optimised away by the SDL compiler on VMS of 1986 or 1987. -- Cheers. Mark Lawrence.