Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'syntax': 0.04; 'python:': 0.09; 'similar,': 0.09; 'statements': 0.09; 'violates': 0.09; 'runs': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; '3):': 0.16; 'abusing': 0.16; 'added.': 0.16; 'benefit.': 0.16; 'determines': 0.16; 'dislike': 0.16; 'notation,': 0.16; 'readability': 0.16; 'statement)': 0.16; 'syntaxerror:': 0.16; 'ternary': 0.16; 'language': 0.16; 'wrote:': 0.18; 'thoughts': 0.19; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'adds': 0.24; 'cheers,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'mention': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; "doesn't": 0.30; 'compared': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'posting': 0.31; '"",': 0.31; 'perl': 0.31; 'piece': 0.31; 'purely': 0.31; 'file': 0.32; 'another': 0.32; 'community': 0.33; '(i.e.': 0.33; 'actual': 0.34; 'knowledge': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'i.e.': 0.36; 'hi,': 0.36; 'two': 0.37; 'list': 0.37; 'list.': 0.37; 'pm,': 0.38; 'rather': 0.38; 'little': 0.38; 'how': 0.40; 'break': 0.61; 'skip:* 10': 0.61; 'first': 0.61; 'kind': 0.63; 'here': 0.66; 'believe': 0.68; 'invalid': 0.68; 'statement,': 0.68; 'superior': 0.69; 'opinions': 0.70; 'lack': 0.78; 'actually,': 0.84; 'sender:addr:chris': 0.84; 'side- effects': 0.84; 'not:': 0.91; 'write:': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=YIBVI6vJxqkipKDak3QsDo1VLzTIcDG6I4/Sg4fB62k=; b=Gsatq62s2xHi8NAOpp/FkdwsBdk198O0g9DyhEG3yq8Jrlnpd2E9rfV+wKIXLlASfc PtzlFF/aV/7I2bWQPPsfwrMJstUkChZVc/RgX+rAETN/itcZyk99WW0byLfxpQm92+3V 5a48nJMyf/0HTJDDOBLVVUdv/KtDm5491OvZk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=YIBVI6vJxqkipKDak3QsDo1VLzTIcDG6I4/Sg4fB62k=; b=DpE9nOSu4aI1UERLI7pNB/ixKCxDrSbLXZOplJ4Rzfz8N9RYaOK1KKvM4lm0KVVe75 b1LO58+AxZUNfectG4s3ivrP1ByfWOHJIXCAb3QmbScsbRDO0hNM3QQrID1otglbDJJ4 5r0QaMQisTHrMR3m3Hv+PzMRDA8UNYAAG1SSxoQIfNJw48ioDFkaB7mc53EDspsha0J4 OEsJDF0Hd9Ucub1BErOp5OWxjwALibqM6gPdEXGyF1XvtUj33Q2VxeBmPPHIJEJkbpE2 Kx9U+hwfd+olPYjcsPcgQ/MocTsG7o8/rtOcvGEi74lP+So+8ZdDRgitvL4IXjCHgVwm 6few== X-Gm-Message-State: ALoCoQnm+woIeyi/BI5Bx7e7f0O7dZaxKw0Lo8IKfpxEPxS979ssSCrCoJVUxaBVgGZdKUSXrTGL MIME-Version: 1.0 X-Received: by 10.43.148.69 with SMTP id kf5mr198511icc.80.1388959755031; Sun, 05 Jan 2014 14:09:15 -0800 (PST) Sender: chris@rebertia.com In-Reply-To: <52C9BF95.5000006@gkayaalp.com> References: <52C9BF95.5000006@gkayaalp.com> Date: Sun, 5 Jan 2014 14:09:14 -0800 X-Google-Sender-Auth: Q7xfVTwKVieBXknJol_fNBLx40k Subject: Re: Postfix conditionals From: Chris Rebert To: =?UTF-8?B?R8O2a3R1xJ8gS2F5YWFscA==?= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python 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: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388959764 news.xs4all.nl 2867 [2001:888:2000:d::a6]:49427 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63230 On Sun, Jan 5, 2014 at 12:24 PM, G=C3=B6ktu=C4=9F Kayaalp wrote: > Hi, > > 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 t= he > two is compared > for readability and intuitiveness. I'm going to have to disagree. I dislike how this obscures the if-statement, complicates the language grammar, and adds another unnecessary way to express the same thing (which violates TOOWTDI) with little countervailing benefit. > We already have a ternary statement that > looks similar, > > py> print('hi') if True else None Actually, to be pedantic, it's a ternary *expression*. Using it purely for side-effects (i.e. as a statement) is rather unidiomatic, in the same way that abusing list comprehensions, e.g.: [print(i) for i in range(42)] is frowned upon. Not to mention that the ternary doesn't work for actual statements (print() is just a function call in Python 3): >>> (x =3D 1) if True else (x =3D 2) File "", line 1 (x =3D 1) if True else (x =3D 2) ^ SyntaxError: invalid syntax > so I reckon there would be no breakage in old code if this kind of syntax > was added. Ruby has > this, and AFAIK Perl also does. > > I lack the knowledge of whether the community has opinions on this kind o= f > notation, so I am > posting this here instead of the ideas list. What are your thoughts on > this? You can already write: for i in [False]: if not i: break if you feel the need for terseness or a one-liner. Perhaps this satisfies your desire? Cheers, Chris