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


Groups > comp.lang.python > #63263 > unrolled thread

Re: Postfix conditionals

Started byTerry Reedy <tjreedy@udel.edu>
First post2014-01-05 21:58 -0500
Last post2014-01-05 21:58 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Postfix conditionals Terry Reedy <tjreedy@udel.edu> - 2014-01-05 21:58 -0500

#63263 — Re: Postfix conditionals

FromTerry Reedy <tjreedy@udel.edu>
Date2014-01-05 21:58 -0500
SubjectRe: Postfix conditionals
Message-ID<mailman.5002.1388977145.18130.python-list@python.org>
On 1/5/2014 3:24 PM, Göktuğ 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
> the two is compared
> for readability and intuitiveness.  We already have a ternary statement

'conditional expression', which happens to be a ternary as opposed to 
binary expression.

> that looks similar,
>
>    py> print('hi') if True else None
>
> 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,

In general, negative on pure duplication. Guido has said he strongly 
dislikes the perl reverse if.

-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web