Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'python,': 0.02; 'perl,': 0.07; 'postfix': 0.07; 'english,': 0.09; 'python:': 0.09; 'runs': 0.10; 'jan': 0.12; 'wrote': 0.14; 'conditional': 0.16; 'determines': 0.16; 'readability': 0.16; 'received:72.5': 0.16; 'received:72.5.230': 0.16; 'received:sender1.zohomail.com': 0.16; 'received:zohomail.com': 0.16; 'wrote:': 0.18; 'properly': 0.19; 'examples': 0.20; 'code,': 0.22; 'example': 0.22; 'header:User- Agent:1': 0.23; 'looks': 0.24; 'equivalent': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'compared': 0.30; 'statement': 0.30; 'code': 0.31; 'easier': 0.31; 'too.': 0.31; 'idea,': 0.31; 'piece': 0.31; 'quite': 0.32; "i'd": 0.34; 'except': 0.35; 'but': 0.35; 'i.e.': 0.36; "didn't": 0.36; 'thanks': 0.36; 'received:192.168.2': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'read': 0.60; 'break': 0.61; 'from:charset:utf-8': 0.61; 'simple': 0.61; 'first': 0.61; 'back': 0.62; 'more': 0.64; 'life': 0.66; 'sample': 0.67; 'believe': 0.68; 'statement,': 0.68; 'results': 0.69; 'superior': 0.69; 'discovered': 0.83; 'newcomer': 0.84; 'not:': 0.91 Date: Mon, 06 Jan 2014 09:51:28 +0200 From: =?UTF-8?B?R8O2a3R1xJ8gS2F5YWFscA==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Postfix conditionals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ZohoMailClient: External X-Zoho-Virus-Status: 2 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388994695 news.xs4all.nl 2932 [2001:888:2000:d::a6]:40450 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63274 On 06-01-2014 03:40, Rhodri James wrote: > On Sun, 05 Jan 2014 20:24:53 -0000, Göktuğ Kayaalp > wrote: > >> AFAIK, we do not have "postfix conditionals" in Python, i.e. a >> condition appended to a statement, which determines whether the >> statement runs or not: > >> py> for i in [False]: >> ... break if not i > >> The above piece of code is equivalent to this in Python: > >> py> for i in [False]: >> ... if not i >> ... break > >> I believe that the first example is superior to the second example >> when the two is compared for readability and intuitiveness. > > In my past life as a newcomer to Perl, I thought this too. Postfix > conditionals read more like English, so they would be easier to take > in and understand. As I wrote more code, I discovered that this > didn't seem to be the case; except in very simple cases, I had to > mentally transpose the conditional back to the start of the statement > to properly comprehend what was going on and what the results would be > for my sample data. > > It looks like a good idea, but I don't think it works that well in > practice. > Thanks for the input! I'd be quite interested in examples which required you to "mentally transpose the conditional back to the start of the statement", by the way. gk