[Python-ideas] if in for-loop statement

Henk-Jaap Wagenaar wagenaarhenkjaap at gmail.com
Thu Feb 23 09:20:34 EST 2017


Hi Paul, Daniel, others,

That is fair enough and the right amount of blunt.

Let me go through the points that were made in that thread (I have not
found any other threads, if someone links to them, I will go through them
as well):

-----

From: https://mail.python.org/pipermail/python-dev/2007-November/075258.html,
alternative solution (in current language):

>     for x in (x for x in range if is_prime(x)):
>         # do something with x

This statement seems overly complicated for what it is trying to achieve
and is semantically much harder to parse than the proposed alternative,
e.g. there is repetition of the string "for x in".

----

A similar point to where I started from in https://mail.python.org/piperm
ail/python-ideas/2016-September/042600.html:

>"Sorry to re-raise this thread--I'm inclined to agree that the case
>doesn't really warrant new syntax.  I just wanted to add that I think
>the very fact that this syntax is supported by list comprehensions is
>an argument *in its favor*.
>
>I could easily see a Python newbie being confused that they can write
>"for x in y if z" inside a list comprehension, but not in a bare
>for-statement.  Sure they'd learn quickly enough that the filtering
>syntax is unique to list comprehensions.  But to anyone who doesn't
>know the historical progression of the Python language that would seem
>highly arbitrary and incongruous I would think.
>
>Just $0.02 USD from a pedagogical perspective.
>
>Erik"

----

The thread Daniel mentioned was ended by the following post
https://mail.python.org/pipermail/python-ideas/2016-September/042285.html

>Generally speaking, we only add new syntax in cases where we're
>prepared to say "In all cases where the new syntax applies, it should
>be used in preference to existing alternative spellings".
>
>Special casing a single "if-continue" in a loop body doesn't meet that
>(deliberately high) bar, with Paul Moore's email going into some more
>detail on the specifics of that.
>
>Cheers,
>Nick."

I am not sure I agree with what he is saying (or I am not following it...).
I think no-one in that thread particularly demonstrated why this could not
supersede all equivalent solutions, even if the if is longer (but not
complex), one can simply do:

for x in range(10) \
         if is_prime(x) and is_overabundant(x) and is_perfect(x) and x != 5:
    # do something with x

where you would line up the if with the range/... on the previous line
(this example is silly, because the conditions cannot be satisfied). This
in my view would still be clearer and more concise than the alternative
solutions.

The emails in the threads seem to indicate that almost everyone is a shade
of grey here, where some really like it (but can life without), some think
it is alright but don't particularly mind, and some think it is not the
worth the cost or would allow abuse. No-one seems to fundamentally hate the
idea, or in a alternative world where it was already in Python, would
suggest taking it out (even if it a backwards-incompatible epoch like 2->3
was approaching) though my reading between the lines of emails can be
wrong. I think Erik's email (see above) shows this most clearly.

In a straw poll at the company I work at everyone was in favour, though
they obviously are not in charge of implementing or changing documentation
so that is easy for them to say, they've got no skin in the game. I don't
know whether it is common for such an idea to be brought up again and again
by newcomers/those who don't strolls the archives enough, but if it keeps
being brought up, and the main argument against is it would take time and
effort to document and implement for little benefit, if Python sticks
around for a long enough time, it will end up taking less time simply
implement it!

Best,
Henk-Jaap

On 23 February 2017 at 13:54, Daniel Moisset <dmoisset at machinalis.com>
wrote:

> Just as a reference, I think the most recent reincarnation of this thread
> was: https://mail.python.org/pipermail/python-ideas/2016-Sep
> tember/042270.html
>
> On 23 February 2017 at 13:46, Paul Moore <p.f.moore at gmail.com> wrote:
>
>> On 23 February 2017 at 13:37, Henk-Jaap Wagenaar
>> <wagenaarhenkjaap at gmail.com> wrote:
>> > Note that this has been suggested before at least once
>> > (https://mail.python.org/pipermail/python-dev/2007-November/075257.html
>> ),
>> > and that thread itself suggests it has been suggested before and
>> shutdown by
>> > Guido (though no source is given for this).
>>
>> Thanks for your interest, but as you note this has already been
>> proposed and rejected (from my personal recollection, more than once).
>>
>> So the key question is surely, what are you proposing that wasn't
>> already discussed in previous threads, and why do you think that the
>> new aspect of your proposal is likely to change Guido's mind?
>>
>> Sorry to be blunt, but rehashing an already extensively discussed idea
>> isn't that productive for anyone.
>>
>> Paul
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
>
> --
> Daniel F. Moisset - UK Country Manager
> www.machinalis.com
> Skype: @dmoisset
>


On 23 February 2017 at 13:54, Daniel Moisset <dmoisset at machinalis.com>
wrote:

> Just as a reference, I think the most recent reincarnation of this thread
> was: https://mail.python.org/pipermail/python-ideas/2016-Sep
> tember/042270.html
>
> On 23 February 2017 at 13:46, Paul Moore <p.f.moore at gmail.com> wrote:
>
>> On 23 February 2017 at 13:37, Henk-Jaap Wagenaar
>> <wagenaarhenkjaap at gmail.com> wrote:
>> > Note that this has been suggested before at least once
>> > (https://mail.python.org/pipermail/python-dev/2007-November/075257.html
>> ),
>> > and that thread itself suggests it has been suggested before and
>> shutdown by
>> > Guido (though no source is given for this).
>>
>> Thanks for your interest, but as you note this has already been
>> proposed and rejected (from my personal recollection, more than once).
>>
>> So the key question is surely, what are you proposing that wasn't
>> already discussed in previous threads, and why do you think that the
>> new aspect of your proposal is likely to change Guido's mind?
>>
>> Sorry to be blunt, but rehashing an already extensively discussed idea
>> isn't that productive for anyone.
>>
>> Paul
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
>
> --
> Daniel F. Moisset - UK Country Manager
> www.machinalis.com
> Skype: @dmoisset
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170223/01e4a152/attachment-0001.html>


More information about the Python-ideas mailing list