Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!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.036 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'attribute': 0.07; 'lookup': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; '*must*': 0.16; 'choose,': 0.16; 'ignoring': 0.16; 'lookups.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'roy': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'logical': 0.24; 'replace': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'url:wiki': 0.31; 'url:wikipedia': 0.31; 'url:org': 0.36; 'two': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'rather': 0.38; 'flow': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'easy': 0.60; 'received:173': 0.61; "you're": 0.61; 'first': 0.61; 'act': 0.63; 'name': 0.63; 'response.': 0.68; 'smith': 0.68; 'article': 0.77; 'beside': 0.84; 'given.': 0.84; 'premature': 0.84; 'received:fios.verizon.net': 0.84; 'wish,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Jan Reedy Subject: Re: Short-circuit Logic Date: Sun, 26 May 2013 17:28:56 -0400 References: <5f101d70-e51f-4531-9153-c92ee2486fd9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369603740 news.xs4all.nl 15896 [2001:888:2000:d::a6]:33211 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46127 On 5/26/2013 4:22 PM, Roy Smith wrote: > In article , > Terry Jan Reedy wrote: > >> On 5/26/2013 7:11 AM, Ahmed Abdulshafy wrote: >> >>> if not allow_zero and abs(x) < sys.float_info.epsilon: >>> print("zero is not allowed") >> >> The reason for the order is to do the easy calculation first and the >> harder one only if the first passes. > > This is a particularly egregious case of premature optimization. You're > worried about how long it takes to execute abs(x)? That's silly. This is a particularly egregious case of premature response. You're ignoring an extra name lookup and two extra attribute lookups. That's silly. That's beside the fact that one *must* choose, so any difference is a reason to act rather than being frozen like Buridan's ass. http://en.wikipedia.org/wiki/Buridan%27s_ass If you wish, replace 'The reason' with 'A reason'. I also the logical flow as better with the order given.