Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63231

Fwd: Re: Postfix conditionals

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.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 <self@gkayaalp.com>
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; 'python,': 0.02; 'syntax': 0.04; 'postfix': 0.07; 'python:': 0.09; 'similar,': 0.09; 'statements': 0.09; 'violates': 0.09; '--------': 0.10; 'runs': 0.10; 'email addr:python.org&gt;': 0.11; 'python': 0.11; 'jan': 0.12; 'posted': 0.15; '3):': 0.16; 'abusing': 0.16; 'added.': 0.16; 'benefit.': 0.16; 'chris,': 0.16; 'determines': 0.16; 'dislike': 0.16; 'notation,': 0.16; 'op.': 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; 'statement)': 0.16; 'syntaxerror:': 0.16; 'ternary': 0.16; 'email addr:python.org,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'thoughts': 0.19; '>>>': 0.22; 'example': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; '&gt;&gt;&gt;': 0.24; 'adds': 0.24; 'cheers,': 0.24; 'looks': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '&gt;': 0.26; '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; "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; 'date:': 0.34; 'knowledge': 0.35; 'there': 0.35; 'i.e.': 0.36; 'hi,': 0.36; 'two': 0.37; 'list': 0.37; 'list.': 0.37; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'rather': 0.38; 'little': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'break': 0.61; 'subject:Fwd': 0.61; 'skip:* 10': 0.61; 'from:charset:utf-8': 0.61; 'first': 0.61; 're:': 0.63; 'kind': 0.63; 'email name :python-list': 0.65; 'here': 0.66; 'reply': 0.66; 'believe': 0.68; 'invalid': 0.68; 'statement,': 0.68; 'superior': 0.69; 'opinions': 0.70; 'lack': 0.78; 'actually,': 0.84; 'rebert': 0.84; 'side- effects': 0.84; 'not:': 0.91; 'write:': 0.91
Date Mon, 06 Jan 2014 00:12:17 +0200
From Göktuğ Kayaalp <self@gkayaalp.com>
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 Fwd: Re: Postfix conditionals
References <CAMZYqRS4xS0VmLOoXdmdbefo=d1f+XMFZ1W8jsyt0Gyo9h4wOg@mail.gmail.com>
In-Reply-To <CAMZYqRS4xS0VmLOoXdmdbefo=d1f+XMFZ1W8jsyt0Gyo9h4wOg@mail.gmail.com>
X-Forwarded-Message-Id <CAMZYqRS4xS0VmLOoXdmdbefo=d1f+XMFZ1W8jsyt0Gyo9h4wOg@mail.gmail.com>
Content-Type multipart/alternative; boundary="------------070602060602040108090007"
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4975.1388959945.18130.python-list@python.org> (permalink)
Lines 207
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1388959945 news.xs4all.nl 2949 [2001:888:2000:d::a6]:51997
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63231

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

This was sent to me as a private reply to a question that I have posted
to python-list@python.org, so I am forwarding it to here.

Chris, please send your messages to the list, and cc the OP.

-------- Original Message --------
Subject: 	Re: Postfix conditionals
Date: 	Sun, 5 Jan 2014 14:09:14 -0800
From: 	Chris Rebert <clp2@rebertia.com>
To: 	Göktuğ Kayaalp <self@gkayaalp.com>
CC: 	Python <python-list@python.org>



On Sun, Jan 5, 2014 at 12:24 PM, Göktuğ Kayaalp <self@gkayaalp.com> 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 the
> 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 = 1) if True else (x = 2)
       File "<stdin>", line 1
         (x = 1) if True else (x = 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 of
> 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



Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Fwd: Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-06 00:12 +0200

csiph-web