Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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; 'value,': 0.04; 'class,': 0.07; 'none,': 0.07; 'subject:code': 0.07; 'implements': 0.09; 'logic': 0.09; 'means,': 0.09; 'cc:addr:python-list': 0.11; 'assume': 0.14; '23,': 0.16; 'a()': 0.16; 'b()': 0.16; 'called,': 0.16; 'clear.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'none.': 0.16; 'roy': 0.16; 'sane': 0.16; 'subclass': 0.16; 'subject:python': 0.16; 'exception': 0.16; 'appropriate': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'instance,': 0.24; 'decide': 0.24; 'mon,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'testing': 0.29; 'thus': 0.29; "doesn't": 0.30; 'dec': 0.30; 'returned': 0.30; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; 'skip:m 30': 0.32; 'reader': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'returning': 0.36; 'done': 0.36; 'doing': 0.36; 'next': 0.36; 'checks': 0.38; 'pm,': 0.38; 'bad': 0.39; 'extremely': 0.39; 'either': 0.39; 'how': 0.40; 'length': 0.61; "you're": 0.61; 'pick': 0.64; 'strategy': 0.64; 'side': 0.67; 'smith': 0.68; 'safe': 0.72; 'forced': 0.84; 'song.': 0.84; 'effects.': 0.91; 'to:none': 0.92; 'imagine': 0.93; '2013': 0.98 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:cc :content-type; bh=o/eSssXeYeTqxHvvysY6ceNmBSsd7/J/y1BrpCZSfws=; b=PLPngKyPMJi1NbkivaMtNSwHH6nucMpmugrAl6u9PZQmJZTqpngqOhWGrhSm1HMiyg knieyiYf2//ySFJ8BtXjGkhRPqnGqqg+5XEZq48JvR7/NZleDryD1KXb1GP2E7ConnMX B4vnzMperFjwo++ePARzKoiGC1+eBD6Pcq2njwQ9WEiRCKRQFELXBpGgx6tPq1Wcef5A Fxf7fnjTbHWyfSD9FUBXoN8lrm83WovE6lqd0xhtA/Oec9oh2PJ77vsOn8oFRzKXm/uh T77GWoytzWmynl/MRPD9ttmG7D6A9YST4I6eXcDP1oBVdhTe7rwc6c8m/APMha7DSjQ3 jrOg== MIME-Version: 1.0 X-Received: by 10.66.102.39 with SMTP id fl7mr22612132pab.43.1387762538435; Sun, 22 Dec 2013 17:35:38 -0800 (PST) In-Reply-To: References: <52b782db$0$6599$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 23 Dec 2013 12:35:38 +1100 Subject: Re: cascading python executions only if return code is 0 From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387762546 news.xs4all.nl 2946 [2001:888:2000:d::a6]:39762 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62576 On Mon, Dec 23, 2013 at 12:24 PM, Roy Smith wrote: > Each SongPicker subclass encapsulates some logic for how to pick the > next song. It can also decide if the strategy it implements is > appropriate for the particular request; create() either returns an > instance of the class, or None. Returning None means, "I'm not the > right picker for this request; try the next one and see what he says". But in that instance, the picker has done nothing. The main effect is to return a value, and since it returned None, you go on to do something else. This looks fine: foo = a() or b() or c() And it also looks like it would be safe to drop one of the calls if you know it won't succeed: if no_way_that_b_will_work: foo = a() or c() The point about side effects is that b() still has to be called, here, and the original statement doesn't make that clear. When you call a function and ignore its return value, you're clearly doing it for its side effects. Imagine this: width_required = max(len(foo),len(bar),len(quux)) Any sane reader is going to assume that the length checks aren't going to have side effects... but they could! Imagine if testing the length of something forced it to be loaded into memory, thus triggering any exception that would otherwise not be triggered until the thing got loaded much later. Vaguely plausible, but bad design because it's extremely unclear. ChrisA