Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(at': 0.03; 'exception': 0.03; 'interpreter': 0.04; 'clause': 0.07; 'exit': 0.07; 'parsing': 0.07; 'subject:question': 0.08; 'explanation': 0.09; 'cc:addr:python-list': 0.10; 'itself.': 0.11; 'block:': 0.16; 'forth.': 0.16; 'loops': 0.16; 'proceeds': 0.16; 'readable': 0.16; 'subject:coding': 0.16; 'wrote:': 0.17; 'else,': 0.17; 'jan': 0.18; '(or': 0.18; 'bit': 0.21; 'supposed': 0.21; 'assuming': 0.22; 'stick': 0.22; 'cc:2**0': 0.23; 'statement': 0.23; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'coding': 0.27; 'question': 0.27; 'andrew': 0.27; 'execution': 0.27; 'subject:/': 0.28; 'overhead': 0.29; 'case,': 0.29; 'evaluation': 0.30; 'function': 0.30; 'sense': 0.31; 'code': 0.31; 'doubt': 0.33; "can't": 0.34; 'continue': 0.35; 'there': 0.35; 'but': 0.36; 'rather': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'possible.': 0.38; 'performance': 0.39; 'skip:" 10': 0.40; 'your': 0.60; 'most': 0.61; 'between': 0.63; 'more': 0.63; 'offer': 0.65; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'special': 0.73; 'manner': 0.74; 'briefly,': 0.84; 'subject:Basic': 0.84; 'cause,': 0.93 Date: Sat, 21 Jul 2012 11:13:02 +0300 From: Jan Riechers User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Andrew Berg Subject: Re: Basic question about speed/coding style/memory References: <500A5B47.1060805@freenet.de> <500A6215.8070703@gmail.com> In-Reply-To: <500A6215.8070703@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: janpeterr@freenet.de 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342858531 news.xs4all.nl 6959 [2001:888:2000:d::a6]:52192 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25729 On 21.07.2012 11:02, Andrew Berg wrote: > On 7/21/2012 2:33 AM, Jan Riechers wrote: >> Block >> ... >> versus this block: >> ... >> Now, very briefly, what is the better way to proceed in terms of >> execution speed, readability, coding style? > Using if/else is the most readable in the general sense. Using return > (or break or continue as applicable) in this manner would indicate (at > least to me) that it's an exceptional or otherwise special case and that > the function can't do what it's supposed to. In that case, I would try > to catch an exception rather than use if/else whenever possible. I > highly doubt there is a significant performance difference between them. > Hello Andrew, Your answer is right, in other circumstances I also would stick to try/except, break-statements in loops and so forth. But the question was a bit more elementary. Cause, as I understand the interpreter chooses either the "else" (1st block) or just proceeds with following code outside the if. So if there is some overhead in some fashion in case we don't offer the else, assuming the interpreter has to exit the evaluation of the "if"-statement clause and return to a "normal parsing code"-state outside the if statement itself. I hope this explanation makes more sense in what I want to ask ;) Jan